unnamed namespace collision

M

Marco Jez

What are the requirements imposed by the Standard on unnamed namespaces? I
mean, is the hidden name guaranteed to be unique across multiple translation
units, or only within the declaring translation unit?

My question comes from a problem I'm seeing with code compiled with MSVC++.
I have multiple files which declare types and variables whose name is the
same across units, but they're declared inside unnamed namespace and so
their fully-qualified name is supposed to be unique. By examining the
assembly listing of each translation unit I see that the compiler gave the
same hidden name to unnamed namespaces in different object files. The funny
thing is that it doesn't happen always...

Any clues?

Marco
 
P

Peter MacMillan

Marco said:
What are the requirements imposed by the Standard on unnamed namespaces? I
mean, is the hidden name guaranteed to be unique across multiple translation
units, or only within the declaring translation unit?

Yes, I think they're supposed to be unique
My question comes from a problem I'm seeing with code compiled with MSVC++.
I have multiple files which declare types and variables whose name is the
same across units, but they're declared inside unnamed namespace and so
their fully-qualified name is supposed to be unique.

Not only are they unique, but they are unknown.
By examining the
assembly listing of each translation unit I see that the compiler gave the
same hidden name to unnamed namespaces in different object files. The funny
thing is that it doesn't happen always...

Any clues?


Yes, the anonymous namespace identifier is unique to the /compilation
unit/. What's happening is that if you have an anonymous namespace in
header foo.h and an anonymous namespace in bar.h, and both are included
in foobar.cpp, then the unique identifier in foo.h and bar.h will be the
same (since they are both part of foobar.cpp).


--
Peter MacMillan
e-mail/msn: (e-mail address removed)
icq: 1-874-927

GCS/IT/L d-(-)>-pu s():(-) a- C+++(++++)>$ UL>$ P++ L+ E-(-) W++(+++)>$
N o w++>$ O !M- V PS PE Y+ t++ 5 X R* tv- b++(+) DI D+(++)>$ G e++ h r--
y(--)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top