| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"Carlos Martinez" |
| Date: |
12 Sep 2006 04:52:09 AM |
| Object: |
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.
.
|
|
| User: "Bart" |
|
| Title: Re: doubt on kinds of linkage |
12 Sep 2006 02:37:36 PM |
|
|
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.
.
|
|
|
| User: "David Harmon" |
|
| Title: Re: doubt on kinds of linkage |
12 Sep 2006 07:16:44 PM |
|
|
On 12 Sep 2006 12:37:36 -0700 in comp.lang.c++, "Bart"
<bart.kowalski@gmail.com> wrote,
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.
.
|
|
|
|
|
| User: "David Harmon" |
|
| Title: Re: doubt on kinds of linkage |
12 Sep 2006 06:28:45 AM |
|
|
On Tue, 12 Sep 2006 11:52:09 +0200 in comp.lang.c++, Carlos Martinez
<cmg250@nospam.tid.es> 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.
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.
.
|
|
|
| User: "Morten V Pedersen" |
|
| Title: Re: doubt on kinds of linkage |
12 Sep 2006 07:48:22 AM |
|
|
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
<cmg250@nospam.tid.es> 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.
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.
.
|
|
|
| User: "David Harmon" |
|
| Title: Re: doubt on kinds of linkage |
12 Sep 2006 01:45:17 PM |
|
|
On Tue, 12 Sep 2006 14:48:22 +0200 in comp.lang.c++, Morten V
Pedersen <mvpe@kom.aau.dk> wrote,
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.
.
|
|
|
|
|
|

|
Related Articles |
|
|