TITLE: anonymous namespaces are open to extension (Newsgroups: comp.std.c++, 24 May 98) PHILLIPPE: > In Stroustrup's C++ 3rd Ed., he mentions that the standards >committee has deprecated the use of keyword 'static' to limit a >declaration/definition to file (translation unit) scope. Instead, he >advises the use of anonymous namespaces. Earlier in the text, he mentions >that namespaces are open, in that declarations/definitions may be added at >any point in time by "reopening" the namespace with "namespace ". >These factors combined have lead me to design the following style of code: > >---some_file.cc--- > >namespace { > void some_function(); >} > >int main( int, char*[] ) { > > // ... > some_function(); > // ... >} > >namespace { > void some_function() { /* ... */ } >} > >---end file--- > >However, my compiler will not link this. I was then told that each >anonymous namespace was unique, which implies that anonymous namespaces are >closed. Is this true? CLAMAGE: stephen.clamage@sun.com (Steve Clamage) No, your compiler is wrong. The unnamed namespace acts like it has a unique name in each different compilation unit, but the same unique name within one compilation unit. Reference: draft standard section 7.3.1.1, "Unnamed namespaces". Your code is OK as you show it.