- Non-const global variables have external linkage by default
- Const global variables have internal linkage by default
- Functions have external linkage by default
- What’s the “static initialization order ‘fiasco’ (problem)”?
- C++ scoped static initialization is not thread-safe, on purpose! (pre-C++11)
- constinit
- static vs std::call_once vs double checked locking
-
- Double-Checked Locking Pattern
const
andstatic
variables don’t have external linkage.
Variables with static storage duration are zero initialised. Note that x has static storage duration even though the static keyword is not used. According to the standard: “All objects which do not have dynamic storage duration, do not have thread storage duration, and are not local have static storage duration”.
Only static_cast
(or C-style casts) can be used to cast an int
to an
enum
. Only reinterpret_cast
(or C-style casts) can be used to cast an int
to a pointer or a pointer to an int
.