Quantcast
Channel: Why should you prefer unnamed namespaces over static functions? - Stack Overflow
Browsing all 12 articles
Browse latest View live

Answer by Lewis Kelsey for Why should you prefer unnamed namespaces over...

The difference is the name of the mangled identifier (_ZN12_GLOBAL__N_11bE vs _ZL1b , which doesn't really matter, but both of them are assembled to local symbols in the symbol table (absence of...

View Article



Answer by Pavel P for Why should you prefer unnamed namespaces over static...

Personally I prefer static functions over nameless namespaces for the following reasons:It's obvious and clear from function definition alone that it's private to the translation unit where it's...

View Article

Answer by masrtis for Why should you prefer unnamed namespaces over static...

A compiler specific difference between anonymous namespaces and static functions can be seen compiling the following code.#include <iostream>namespace{ void unreferenced() { std::cout <<...

View Article

Answer by Chris for Why should you prefer unnamed namespaces over static...

In addition if one uses static keyword on a variable like this example:namespace { static int flag;}It would not be seen in the mapping file

View Article

Answer by Don Wakefield for Why should you prefer unnamed namespaces over...

From experience I'll just note that while it is the C++ way to put formerly-static functions into the anonymous namespace, older compilers can sometimes have problems with this. I currently work with a...

View Article


Answer by Richard Corden for Why should you prefer unnamed namespaces over...

There is one edge case where static has a surprising effect(at least it was to me). The C++03 Standard states in 14.6.4.2/1:For a function call that depends on a template parameter, if the function...

View Article

Answer by William Knight for Why should you prefer unnamed namespaces over...

I recently began replacing static keywords with anonymous namespaces in my code but immediately ran into a problem where the variables in the namespace were no longer available for inspection in my...

View Article

Answer by hazzen for Why should you prefer unnamed namespaces over static...

Putting methods in an anonymous namespace prevents you from accidentally violating the One Definition Rule, allowing you to never worry about naming your helper methods the same as some other method...

View Article


Answer by Firas Assaad for Why should you prefer unnamed namespaces over...

Use of static keyword for that purpose is deprecated by the C++98 standard. The problem with static is that it doesn't apply to type definition. It's also an overloaded keyword used in different ways...

View Article


Answer by Commodore Jaeger for Why should you prefer unnamed namespaces over...

Having learned of this feature only just now while reading your question, I can only speculate. This seems to provide several advantages over a file-level static variable:Anonymous namespaces can be...

View Article

Answer by luke for Why should you prefer unnamed namespaces over static...

The C++ Standard reads in section 7.3.1.1 Unnamed namespaces, paragraph 2:The use of the static keyword isdeprecated when declaring objects in anamespace scope, the unnamed-namespaceprovides a superior...

View Article

Why should you prefer unnamed namespaces over static functions?

A feature of C++ is the ability to create unnamed (anonymous) namespaces, like so:namespace { int cannotAccessOutsideThisFile() { ... }} // namespaceYou would think that such a feature would be useless...

View Article
Browsing all 12 articles
Browse latest View live




Latest Images