>>> I don't think things inside anonymous namespaces *need* internal
>>Thanks for your response. The question then is, why does the standard
>>mandate internal linkage on namespaces inside unnamed namespaces,
>>whereas it defines normal linkage (i.e. external by default) for
>The entire point and only purpose of an unnamed namespace is to
>prevent the contents from having external linkage.
As Martin pointed out to me in private email, I misspoke.
Members of the unnamed namespace have external linkage,
but you can't write the external name from any other
translation unit. That is, the effect is as if the
unnamed namespace has a special hidden name that only
the compiler knows or can use.
The effect is almost the same as if the members have
internal linkage, so I find it helpful to think of the
unnamed namespace as creating an area of internal linkage.
Unfortunately, I got tripped up by the exception to that
(technically incorrect) mental model.
The exception is that you can use members of an unnamed
namespace as template parameters. That means in general
(when the template implementation is separately compiled)
that the template parameters need external linkage.
There is one special additional rule (3.5 Program and linkage,
paragraph 4) that the name of a namespace declared within an
unnamed namespace does not have external linkage.
Martin was asking for the reason for that special rule, and
I don't know the answer to that.
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]