[Qt-creator] unnamed namespace and internal linkage
Christian Kandeler
christian.kandeler at theqtcompany.com
Tue Sep 22 13:25:53 CEST 2015
On 09/22/2015 01:12 PM, Lorenz Haas wrote:
> our coding style states that
>
> "Use static keywords instead of anonymous namespaces whenever
> possible. A name localized to the compilation unit with static is
> guaranteed to have internal linkage. For names declared in anonymous
> namespaces, the C++ standard unfortunately mandates external linkage
> (ISO/IEC 14882, 7.1.1/6, or see various discussions about this on the
> gcc mailing lists)."
>
> After "hours" of studying the standard (C++11) I came to the
> conclusion that this changed in C++11 and anonymous namespaces have
> internal linkage:
>
> ยง 5.5/4: "An unnamed namespace or a namespace declared directly or
> indirectly within an unnamed namespace has internal linkage"
>
> Can someone confirm that or reject. My C++ Standard knowledge is -
> somehow - limited :) If it is true, we could alter our coding styles.
I don't know, but shouldn't the "static" keyword be preferred anyway due
to being less noisy? I think the main reason people were using anonymous
namespaces instead was that "static" (in that context) was deprecated in
C++98, but that decision has been reversed in C++11.
Christian
More information about the Qt-creator
mailing list