Skip to main content
members of (anonymous => unnamed) NSes have internal linkage; tidy up
Source Link
Potatoswatter
  • 138.8k
  • 29
  • 281
  • 435

Your analysis is correct, but doesn't necessarily imply uselessness. Even if most compilers do automatically inline functions (reason #1), it's best to declare inline just to describe intent.

Disregarding interaction with inline, static functions should be used sparingly. The static modifier at namespace scope was formerly deprecated in favor of anonymousunnamed namespaces (C++03 §D.2). For some obscure reason that I can't recall it was removed from deprecation in C++11 but you should seldom need to declare anything with internal linkageit.

So, Practically marking a function static and inline both has no use at all. Either it should be static(not most preferred) or inline(most preferred),

There's no notion of preference. static implies that multipledifferent functions with the same namesignature may exist within different definitions.cpp files (translation units). inline without static means that it's OK for different translation units to define the same function with identical definitions.

What is preferred is to use an anonymousunnamed namespace instead of static:

namespace { inline void better(); // give the function a unique name } static inline void worse(); // kludge the linker to allowing duplicates 

Your analysis is correct, but doesn't necessarily imply uselessness. Even if most compilers do automatically inline functions (reason #1), it's best to declare inline just to describe intent.

Disregarding interaction with inline, static functions should be used sparingly. The static modifier at namespace scope was formerly deprecated in favor of anonymous namespaces (C++03 §D.2). For some obscure reason that I can't recall it was removed from deprecation in C++11 but you should seldom need to declare anything with internal linkage.

So, Practically marking a function static and inline both has no use at all. Either it should be static(not most preferred) or inline(most preferred),

There's no notion of preference. static implies that multiple functions with the same name may exist with different definitions. inline means that it's OK for different translation units to define the same function with identical definitions.

What is preferred is to use an anonymous namespace instead of static:

namespace { inline void better(); // give the function a unique name } static inline void worse(); // kludge the linker to allowing duplicates 

Your analysis is correct, but doesn't necessarily imply uselessness. Even if most compilers do automatically inline functions (reason #1), it's best to declare inline just to describe intent.

Disregarding interaction with inline, static functions should be used sparingly. The static modifier at namespace scope was formerly deprecated in favor of unnamed namespaces (C++03 §D.2). For some obscure reason that I can't recall it was removed from deprecation in C++11 but you should seldom need it.

So, Practically marking a function static and inline both has no use at all. Either it should be static(not most preferred) or inline(most preferred),

There's no notion of preference. static implies that different functions with the same signature may exist in different .cpp files (translation units). inline without static means that it's OK for different translation units to define the same function with identical definitions.

What is preferred is to use an unnamed namespace instead of static:

namespace { inline void better(); // give the function a unique name } static inline void worse(); // kludge the linker to allowing duplicates 
added 652 characters in body
Source Link
Potatoswatter
  • 138.8k
  • 29
  • 281
  • 435

Your analysis is correct, but doesn't necessarily imply uselessness. Even if most compilers do automatically inline functions (reason #1), it's best to declare inline just to describe intent.

Disregarding interaction with inline, static functions should be used sparingly. The static modifier at namespace scope was formerly deprecated in favor of anonymous namespaces (C++03 §D.2). For some obscure reason that I can't recall it was removed from deprecation in C++11 but you should seldom need to declare anything with internal linkage.

So, Practically marking a function static and inline both has no use at all. Either it should be static(not most preferred) or inline(most preferred),

There's no notion of preference. static implies that multiple functions with the same name may exist with different definitions. inline means that it's OK for different translation units to define the same function with identical definitions.

What is preferred is to use an anonymous namespace instead of static:

namespace { inline void better(); // give the function a unique name } static inline void worse(); // kludge the linker to allowing duplicates 

Your analysis is correct, but doesn't necessarily imply uselessness. Even if most compilers do automatically inline functions (reason #1), it's best to declare inline just to describe intent.

Disregarding interaction with inline, static functions should be used sparingly. The static modifier at namespace scope was formerly deprecated in favor of anonymous namespaces (C++03 §D.2). For some obscure reason that I can't recall it was removed from deprecation in C++11 but you should seldom need to declare anything with internal linkage.

Your analysis is correct, but doesn't necessarily imply uselessness. Even if most compilers do automatically inline functions (reason #1), it's best to declare inline just to describe intent.

Disregarding interaction with inline, static functions should be used sparingly. The static modifier at namespace scope was formerly deprecated in favor of anonymous namespaces (C++03 §D.2). For some obscure reason that I can't recall it was removed from deprecation in C++11 but you should seldom need to declare anything with internal linkage.

So, Practically marking a function static and inline both has no use at all. Either it should be static(not most preferred) or inline(most preferred),

There's no notion of preference. static implies that multiple functions with the same name may exist with different definitions. inline means that it's OK for different translation units to define the same function with identical definitions.

What is preferred is to use an anonymous namespace instead of static:

namespace { inline void better(); // give the function a unique name } static inline void worse(); // kludge the linker to allowing duplicates 
Source Link
Potatoswatter
  • 138.8k
  • 29
  • 281
  • 435

Your analysis is correct, but doesn't necessarily imply uselessness. Even if most compilers do automatically inline functions (reason #1), it's best to declare inline just to describe intent.

Disregarding interaction with inline, static functions should be used sparingly. The static modifier at namespace scope was formerly deprecated in favor of anonymous namespaces (C++03 §D.2). For some obscure reason that I can't recall it was removed from deprecation in C++11 but you should seldom need to declare anything with internal linkage.