A
Asfand Yar Qazi
For years, I've been putting everything that won't be needed outside a
compilation unit in anonymous namespaces, even editing my old files that did
things the 'old' way (using static linkage). Then suddenly I find this in the
KDE developer faq:
Q: 2.24. I put some functions in anonymous namespace and someone reverted it
and made those functions static, why?
Symbols defined in a C++ anonymous namespace do NOT have internal linkage.
Anonymous namespaces only give an unique name for that translation unit and
that is it; they don't change the linkage of the symbol at all. Linkage isn't
changed on those because the second phase of two-phase name lookup ignores
functions with internal linkages. Also, entities with internal linkage cannot
be used as template arguments
Is that true? What are the implications of this? Should I now go around all
my source files and make functions/global variables declared in them static?
compilation unit in anonymous namespaces, even editing my old files that did
things the 'old' way (using static linkage). Then suddenly I find this in the
KDE developer faq:
Q: 2.24. I put some functions in anonymous namespace and someone reverted it
and made those functions static, why?
Symbols defined in a C++ anonymous namespace do NOT have internal linkage.
Anonymous namespaces only give an unique name for that translation unit and
that is it; they don't change the linkage of the symbol at all. Linkage isn't
changed on those because the second phase of two-phase name lookup ignores
functions with internal linkages. Also, entities with internal linkage cannot
be used as template arguments
Is that true? What are the implications of this? Should I now go around all
my source files and make functions/global variables declared in them static?