473,388 Members | 1,327 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

doubt on kinds of linkage

Hi all:

I have old pieces of code like this:

//distsgip.cc
const RWCString var1;

//ReceptorDistIP.cc
extern const RWCString var1;

I don't like to use extern, but it is not my code.

I have a linkage error with var1 (undefined symbol)

If I remove const in both cases, code compiles and links ok.

¿Have a different linkage const and not const variables?

¿How can I solve the problem mantaining const?

Thanks in advance.
Sep 12 '06 #1
5 1405
On Tue, 12 Sep 2006 11:52:09 +0200 in comp.lang.c++, Carlos Martinez
<cm****@nospam.tid.eswrote,
>I have old pieces of code like this:

//distsgip.cc
const RWCString var1;

//ReceptorDistIP.cc
extern const RWCString var1;

I don't like to use extern, but it is not my code.
There is nothing wrong with extern!
>I have a linkage error with var1 (undefined symbol)

//distsgip.cc
extern const RWCString var1;
const RWCString var1;

Yes, it's true. Put both lines in.

Or put the "extern" declaration in a header and include it in both
distsgip.cc and ReceptorDistIP.cc if you want to go that way.

Sep 12 '06 #2
Hi,
A const can be given external linkage by an explicit declaration:

In your case it should be:

//distsgip.cc
extern const RWCString var1;

//ReceptorDistIP.cc
extern const RWCString var1;

// morten

David Harmon wrote:
On Tue, 12 Sep 2006 11:52:09 +0200 in comp.lang.c++, Carlos Martinez
<cm****@nospam.tid.eswrote,
>I have old pieces of code like this:

//distsgip.cc
const RWCString var1;

//ReceptorDistIP.cc
extern const RWCString var1;

I don't like to use extern, but it is not my code.

There is nothing wrong with extern!
>I have a linkage error with var1 (undefined symbol)


//distsgip.cc
extern const RWCString var1;
const RWCString var1;

Yes, it's true. Put both lines in.

Or put the "extern" declaration in a header and include it in both
distsgip.cc and ReceptorDistIP.cc if you want to go that way.
Sep 12 '06 #3
On Tue, 12 Sep 2006 14:48:22 +0200 in comp.lang.c++, Morten V
Pedersen <mv**@kom.aau.dkwrote,
>Hi,
A const can be given external linkage by an explicit declaration:

In your case it should be:

//distsgip.cc
extern const RWCString var1;

//ReceptorDistIP.cc
extern const RWCString var1;

// morten
But of course if that is all you have then var1 will end up as an
"unresolved extern" at link time! You need the other part too.

Sep 12 '06 #4
Carlos Martinez wrote:
I have old pieces of code like this:

//distsgip.cc
const RWCString var1;

//ReceptorDistIP.cc
extern const RWCString var1;

I don't like to use extern, but it is not my code.

I have a linkage error with var1 (undefined symbol)
Of course, it's a constant so you need to initialize it somewhere. In
one of the files you must have:

const RWCString var1 = <constant expression>;

Regards,
Bart.

Sep 12 '06 #5
On 12 Sep 2006 12:37:36 -0700 in comp.lang.c++, "Bart"
<ba***********@gmail.comwrote,
>Of course, it's a constant so you need to initialize it somewhere. In
one of the files you must have:

const RWCString var1 = <constant expression>;
No, the class default constructor may be all you need to initialize
that particular instance. We have no idea what the default
constructor says. I do agree that it would be wise to be a bit
suspicious of the lack of initialization parameters, but it is
perhaps only Carlos's simplified example for purposes of the
question.

Sep 13 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: qazmlp | last post by:
const has internal linkage in C++, but external linkage in C. Am I right ? But, linker reports multiply-defined error if the following header is included in multiple .cpp files. //...
47
by: Richard Hayden | last post by:
Hi, I have the following code: /******************************** file1.c #include <iostream> extern void dummy(); inline int testfunc() {
20
by: Grumble | last post by:
Hello everyone, As far as I understand, the 'inline' keyword is a hint for the compiler to consider the function in question as a candidate for inlining, yes? What happens when a function with...
10
by: Mark A. Gibbs | last post by:
I have a question about mixing C and C++. In a C++ translation unit, I want to define a function with internal linkage and C calling convention. Here's a sample of what I want to do: //...
5
by: pembed2003 | last post by:
Hi all, I am reading the book "C How to Program" and in the chapter where it discuss scope rule, it says there are four scopes for a variable: function scope file scope block scope...
3
by: al.cpwn | last post by:
do static and inline functions or members have internal linkage? I have been reading this newsgroup on google and found conflicting ideas. Can someone please help me understand why in some places...
13
by: fctk | last post by:
source: http://rm-f.net/~orange/devel/specifications/c89-draft.html#3.1.2.2 there are two passages in this paragraph i can't fully understand: 1) "If the declaration of an identifier for an...
11
by: Bob Nelson | last post by:
I don't remember seeing the term ``doubt'' used much in c.l.c. back in the 90's. When did this word become nearly synonymous with ``question'' or ``query'' and does it have static duration?
11
by: whirlwindkevin | last post by:
I saw a program source code in which a variable is defined in a header file and that header file is included in 2 different C files.When i compile and link the files no error is being thrown.How is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.