Why doesn’t this “undefined extern variable” result in a linker error in C++17?

Because the variable isn’t odr-used. You have a constexpr if there that always discards the branch that could use it. One of the points of constexpr if is that the discarded branch need not even compile, only be well-formed. That’s how we can place calls to non-existing member functions in a discarded branch.

How to name a constant in Objective-C?

After a bit of googling I’ve found the official coding guidelines for Cocoa. To sum up: Start with a two- or three-letter prefix in ALL-CAPS Rest in UpperCamelCase Same criteria for extern constants I agree with itaiferber that the k prefix style is clearer and also much more useful for autocompletion. It would be interesting … Read more

Is extern “C” only required on the function declaration?

The ‘extern “C”‘ should not be required on the function defintion as long as the declaration has it and is already seen in the compilation of the definition. The standard specifically states (7.5/5 Linkage specifications): A function can be declared without a linkage specification after an explicit linkage specification has been seen; the linkage explicitly … Read more

What’s the difference between static inline, extern inline and a normal inline function?

A function definition with static inline defines an inline function with internal linkage. Such function works “as expected” from the “usual” properties of these qualifiers: static gives it internal linkage and inline makes it inline. So, this function is “local” to a translation unit and inline in it. A function definition with just inline defines … Read more

Should functions be made “extern” in header files?

From The C Book: If a declaration contains the extern storage class specifier, or is the declaration of a function with no storage class specifier (or both), then: If there is already a visible declaration of that identifier with file scope, the resulting linkage is the same as that of the visible declaration; otherwise the … Read more

using extern template (C++11) to avoid instantiation

You should only use extern template to force the compiler to not instantiate a template when you know that it will be instantiated somewhere else. It is used to reduce compile time and object file size. For example: // header.h template<typename T> void ReallyBigFunction() { // Body } // source1.cpp #include “header.h” void something1() { … Read more

What does the extern keyword mean?

extern gives a name external linkage. This means that the object or function is accessible through this name from other translation units in the program. For functions, this is the default linkage in any case so its usage (in this context) is usually redundant.