By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,301 Members | 1,366 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,301 IT Pros & Developers. It's quick & easy.

unnamed namespace collision

P: n/a
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
Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Marco Jez wrote:
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).

Marco

--
Peter MacMillan
e-mail/msn: pe***@writeopen.com
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(--)
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.