Shared/CommonBase.h file

Basic definitions.

Some configuration-specific and platform-specific definitions, including DEATH_TARGET_*, are listed separately. Some of them are supplied via a compiler flag by CMake, the rest of them also requires this header file to work properly.

Defines

#define DEATH_CXX_STANDARD
C++ standard version.
#define DEATH_LONG_DOUBLE_SAME_AS_DOUBLE
Whether long double has the same precision as double
#define DEATH_SOURCE_LOCATION_BUILTINS_SUPPORTED
Whether source location built-ins are supported.
#define DEATH_DEPRECATED(message)
Deprecation mark.
#define DEATH_IGNORE_DEPRECATED_PUSH
Begin code section with deprecation warnings ignored.
#define DEATH_IGNORE_DEPRECATED_POP
End code section with deprecation warnings ignored.
#define DEATH_UNUSED
Unused variable mark.
#define DEATH_FALLTHROUGH
Switch case fall-through.
#define DEATH_THREAD_LOCAL
Thread-local annotation.
#define DEATH_CONSTEXPR14
C++14 constexpr annotation.
#define DEATH_CONSTEXPR20
C++20 constexpr annotation.
#define DEATH_ALWAYS_INLINE
Always inline a function.
#define DEATH_NEVER_INLINE
Never inline a function.
#define DEATH_RESTRICT
Hint for compiler that a variable isn't aliased in the current scope.
#define DEATH_ASSUME(condition)
Hint for compiler to assume a condition.
#define DEATH_LIKELY(...)
Mark an if condition as likely to happen.
#define DEATH_UNLIKELY(...)
Mark an if condition as unlikely to happen.
#define DEATH_PASSTHROUGH(...)
Passthrough.
#define DEATH_NOOP(...)
No-op.
#define DEATH_PASTE(a, b)
Paste two tokens together.
#define DEATH_LINE_STRING
Line number as a string.

Define documentation

#define DEATH_CXX_STANDARD

C++ standard version.

Expands to __cplusplus macro on all sane compilers; on MSVC uses _MSVC_LANG if defined (since Visual Studio 2015 Update 3), otherwise reports C++11. The returned version is:

  • 201103 when C++11 is used
  • 201402 when C++14 is used
  • 201703 when C++17 is used
  • 202002 when C++20 is used
  • greater than 202002 when C++2b is used

Note that compilers that don't have full support for given standard may not return the exact value, in which case it's recommended to check that the reported value is greater than the previous standard, for example #if DEATH_CXX_STANDARD > 201703 to test whether compiling as C++20.

#define DEATH_LONG_DOUBLE_SAME_AS_DOUBLE

Whether long double has the same precision as double

Defined on platforms where the long double type has a 64-bit precision instead of 80-bit, thus same as double. It's the case for MSVC (source), 32-bit Android, Emscripten and Mac (but not iOS) with ARM processors. Emscripten is a bit special because it's long double is sometimes 80-bit, but its precision differs from the 80-bit representation elsewhere, so it's always treated as 64-bit. Note that even though the type size and precision may be the same, these are still two distinct types, similarly to how int and signed int behave the same but are treated as different types.

#define DEATH_SOURCE_LOCATION_BUILTINS_SUPPORTED

Whether source location built-ins are supported.

Defined if compiler-specific builtins used to implement the C++20 std::source_location feature are available. Defined on GCC at least since version 4.8, Clang 9+ and MSVC 2019 16.6 and newer; on all three they're present also in the C++11 mode.

#define DEATH_DEPRECATED(message)

Deprecation mark.

Marked function, class or typedef will emit deprecation warning on supported compilers (GCC, Clang, MSVC).

#define DEATH_IGNORE_DEPRECATED_PUSH

Begin code section with deprecation warnings ignored.

Suppresses compiler warnings when using a deprecated API (GCC, Clang, MSVC). Useful when testing or writing APIs that depend on deprecated functionality. In order to avoid warning suppressions to leak, for every DEATH_IGNORE_DEPRECATED_PUSH there has to be a corresponding DEATH_IGNORE_DEPRECATED_POP.

#define DEATH_IGNORE_DEPRECATED_POP

End code section with deprecation warnings ignored.

See DEATH_IGNORE_DEPRECATED_PUSH for more information.

#define DEATH_UNUSED

Unused variable mark.

Putting this before unused variable will suppress compiler warning about it being unused. If possible, use static_cast<void>(var) or nameless function parameters instead.

#define DEATH_FALLTHROUGH

Switch case fall-through.

Suppresses a warning about a case fallthrough in a switch. Expected to be put at a place where a break; would usually be

#define DEATH_THREAD_LOCAL

Thread-local annotation.

Expands to C++11 thread_local keyword on all compilers except old Apple Clang, where it's defined as __thread. Note that the pre-standard __thread has some semantic differences, in particular regarding RAII.

#define DEATH_CONSTEXPR14

C++14 constexpr annotation.

Expands to constexpr if C++14 or newer standard is enabled and if the compiler implements C++14 relaxed constexpr rules (which includes GCC 5+, Clang 3.5+ and MSVC 2017+).

#define DEATH_CONSTEXPR20

C++20 constexpr annotation.

Expands to constexpr if C++20 or newer standard is enabled and if the compiler implements all C++20 constexpr language additions such as trivial default initialization (which includes GCC 10+, Clang 10+ and MSVC 2019 19.29+).

#define DEATH_ALWAYS_INLINE

Always inline a function.

Stronger than the standard inline keyword where supported, but even then the compiler might decide to not inline the function (for example if it's recursive). Expands to __attribute__((always_inline)) inline on GCC and Clang (both keywords need to be specified, docs), to __forceinline on MSVC (docs) and to just inline elsewhere. On GCC and Clang this makes the function inline also in Debug mode (-g), while on MSVC compiling in Debug (/Ob0) always suppresses all inlining.

#define DEATH_NEVER_INLINE

Never inline a function.

Prevents the compiler from inlining a function during an optimization pass. Expands to __attribute__((noinline)) on GCC and Clang (docs), to __declspec(noinline) on MSVC (docs) and is empty elsewhere.

#define DEATH_RESTRICT

Hint for compiler that a variable isn't aliased in the current scope.

This macro provides a hint to the compiler that for the lifetime of the pointer, no other pointer will be used to access the object it points to.

#define DEATH_ASSUME(condition)

Hint for compiler to assume a condition.

This macro does not handle the case when the condition isn't true in any way — only provides a hint to the compiler, possibly improving performance.

#define DEATH_LIKELY(...)

Mark an if condition as likely to happen.

Since branch predictors of contemporary CPUs do a good enough job already, the main purpose of this macro is to affect assembly generation and instruction cache use in hot loops — for example, when a certain condition is likely to happen each iteration, the compiler may put code of the else branch in a "cold" section of the code, ensuring the more probable code path stays in the cache.

#define DEATH_UNLIKELY(...)

Mark an if condition as unlikely to happen.

An inverse to DEATH_LIKELY(), see its documentation for more information about suggested use and expected impact on performance. Useful to mark boundary conditions in tight loops.

#define DEATH_PASSTHROUGH(...)

Passthrough.

Expands to all arguments passed to it. Inverse of DEATH_NOOP().

#define DEATH_NOOP(...)

No-op.

Eats all arguments passed to it. Inverse of DEATH_PASSTHROUGH(). Useful on compilers that don't support defining function macros on command line

#define DEATH_PASTE(a, b)

Paste two tokens together.

Concatenates preprocessor tokens to create a new one. However, two tokens that don't together form a valid token cannot be pasted together.

#define DEATH_LINE_STRING

Line number as a string.

Turns the standard __LINE__ macro into a string. Useful for example to have correct line numbers when embedding GLSL shaders directly in the code.