473,549 Members | 2,531 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

unnamed namespace collision

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
1 2153
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2340
by: Sandy | last post by:
Hi, I have two files as folllows file1.cpp #include<iostream> using namespace std; namespace { void show(); void fun() { cout<<"fun called\n"; } }
2
1266
by: dioscuroi | last post by:
Is there any difference between declaring in unnamed namespace and i global namespace? I can't recognize this p.s: Have a nice day ^_________ -
8
2024
by: Simon Brooke | last post by:
I was debugging a new XML generator tonight and trying to determine why it wasn't working; and realised my dom printer does not output XML namespace declarations. My method to output an Element is as follows: /** * Print an element node, and, by recursive descent, it's children * * @param node the node to print
9
5409
by: Ivan Mascovich | last post by:
Previous posts (and compilers) confirm that class X { friend void Y() ; } ; does not match namespace
3
2595
by: Tomás | last post by:
I have a header file/source file combo. There's approximately five functions in the source file. Only one of the functions should be used by other translation units, so I've defined the other four functions within an unnamed namespace. The header file only contains a declaration for the one function. My function needs to call the other...
1
2007
by: vsgdp | last post by:
I just want to clarify: Say I have a helper class that is only used in one translation file (e.g., a predicate class). I don't want the name of this class to conflict with other class names in other files, so I put it in a nameless namespace?
7
2216
by: patrick | last post by:
Why do some code listings for learning C++ have the entire namespace std being used while others just specify the parts they want to use?
1
3895
by: raylopez99 | last post by:
I seem to get name collision between the Generic collection SortedList and C++.NET Framework collection SortedList. How to resolve? Here are the libraries that seem to clash: System::Collections::SortedList, System::Collections::Generic::SortedList, using namespace System::Collections; using namespace System::Collections::Generic; ...
3
2268
by: CrazyJohn | last post by:
Hi guys, This is my first time posting question here, if I break any rules, please kindly point out. And I'm really glad to be a part of this community. Here is my question, Our lecturer told us that Unnamed Namespace is an alternative to Static Internal Variables, but he also said that Namespace has an
0
7526
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7457
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7483
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7817
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5375
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3487
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1949
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1063
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
771
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.