c++ - Why an unnamed namespace is a "superior" alternative to static? -
this question has answer here:
the section $7.3.1.1/2 c++ standard reads:
the use of static keyword deprecated when declaring objects in namespace scope; unnamed-namespace provides a superior alternative.
i don't understand why unnamed namespace considered superior alternative? rationale? i've known long time standard says, i've never thought it, when replying question: superiority of unnamed namespace on static?
is considered superior because can applied user-defined types well, described in answer? or there other reason well, i'm unaware of? i'm asking this, particularly because reasoning in answer, while standard might have else in mind.
- as you've mentioned, namespace works anything, not functions , objects.
- as greg has pointed out,
static
means many things already. - namespaces provide uniform , consistent way of controlling visibility @ global scope. don't have use different tools same thing.
- when using anonymous namespace, function/object name mangled properly, allows see "(anonymous namespace)::xyz" in symbol table after de-mangling, , not "xyz" static linkage.
- as pointed out in comments below, isn't allowed use static things template arguments, while anonymous namespaces it's fine.
- more? probably, can't think of else right now.
Comments
Post a Comment