Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • In the example the static is needed in order to avoid the function having external linkage. As it will be implemented in every module that uses the header, the linker might object if the static keyword is not present. Commented Oct 8, 2010 at 14:11
  • @Alexander: Well, inline will allow multiple definitions of the function. And in my opinion is a superior alternative. However, if "INTERNAL LINKAGE" is exactly what is needed, then unnamed namespace is much better, at least because it is not deprecated. Commented Oct 8, 2010 at 14:15
  • 4
    inline allows multiple identical definitions of the function. static allows multiple different definitions, since each translation unit has its own function with internal linkage, they just happen to be referred to by the same name. So, if there's something in the definition of func that depends on some #defines (such as assert), and you want it to be legal to combine different TUs that included the header with different values in the #define, then you'd need either static or an unnamed namespace. inline won't do, officially, although in practice it might work. Commented Oct 8, 2010 at 15:19
  • If internal linkage is exactly what is required then an unnamed namespace is not sufficient. While it may be a technicality, members of an unnamed namespace (other than other namespaces) have external linkage by default. Commented Oct 8, 2010 at 23:10
  • My FCD says "Although entities in an unnamed namespace might have external linkage, they are effectively qualified by a name unique to their translation unit and therefore can never be seen from any other translation unit." Commented Oct 9, 2010 at 0:10