Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
|
Go to the source code of this file.
Macros | |
#define | UNUSED(param) |
mark a function parameter as unused and avoid the corresponding compiler warning. More... | |
#define | UNUSED2(param) ((void)(param)) |
mark a function local variable or parameter as unused and avoid the corresponding compiler warning. More... | |
#define | NOTHROW_DECLARE |
indicate a function will not throw any synchronous exceptions, thus hopefully generating smaller and more efficient code. More... | |
#define | NOTHROW_DEFINE |
#define | ANALYZER_NORETURN |
mark a function as noreturn for static analyzer purposes. More... | |
#define | UNREACHABLE |
"unreachable code" helpers More... | |
#define | HAVE_ASSUME_UNREACHABLE 1 |
#define | ASSUME_UNREACHABLE |
#define | HAVE_ASSUME_UNREACHABLE 0 |
#define | UNREACHABLE |
"unreachable code" helpers More... | |
#define | NODEFAULT default: UNREACHABLE |
convenient specialization of UNREACHABLE for switch statements whose default can never be reached. More... | |
#define | PASTE3_HIDDEN__(a, b, c) a ## b ## c |
#define | PASTE3__(a, b, c) PASTE3_HIDDEN__(a, b, c) |
#define | UID__ PASTE3__(LINE_, __LINE__, _) |
#define | UID2__ PASTE3__(LINE_, __LINE__, _2) |
#define | cassert(expr) static_assert((expr), #expr) |
Compile-time assertion. More... | |
#define | NONCOPYABLE(className) |
Indicates that a class is noncopyable (usually due to const or reference members, or because the class works as a singleton). More... | |
#define | MOVABLE(className) |
Indicates that move semantics can be used, so that a NONCOPYABLE class can still be assigned by taking over the reference to the value. More... | |
#define | ASSUME_ALIGNED(ptr, multiple) |
#define | PRINTF_ARGS(fmtpos) |
#define | VPRINTF_ARGS(fmtpos) |
#define | WPRINTF_ARGS(fmtpos) |
#define | VWPRINTF_ARGS(fmtpos) |
#define | SENTINEL_ARG |
#define | COMPILER_FENCE |
prevent the compiler from reordering loads or stores across this point. More... | |
#define | _W64 |
#define | RESTRICT |
#define | ARRAY_SIZE(name) (sizeof(*ArraySizeDeducer(name))) |
#define | __func__ "(unknown)" |
#define | EXTERN_C extern |
#define | INLINE inline |
#define | CALL_CONV |
#define | DECORATED_NAME(name) name |
#define | STRINGIZE2(id) # id |
#define | STRINGIZE(id) STRINGIZE2(id) |
#define | WIDEN2(x) L ## x |
#define | WIDEN(x) WIDEN2(x) |
#define | FALLTHROUGH |
Functions | |
template<typename T > | |
void | ignore_result (const T &) |
Silence the 'unused result' warning. More... | |
template<typename T , size_t n> | |
char(* | ArraySizeDeducer (T(&)[n]))[n] |
#define __func__ "(unknown)" |
#define _W64 |
#define ANALYZER_NORETURN |
mark a function as noreturn for static analyzer purposes.
currently only for clang-analyzer.
#define ARRAY_SIZE | ( | name | ) | (sizeof(*ArraySizeDeducer(name))) |
#define ASSUME_ALIGNED | ( | ptr, | |
multiple | |||
) |
#define ASSUME_UNREACHABLE |
#define CALL_CONV |
#define cassert | ( | expr | ) | static_assert((expr), #expr) |
Compile-time assertion.
Causes a compile error if the expression evaluates to zero/false.
No runtime overhead; may be used anywhere, including file scope. Especially useful for testing sizeof types.
expr | Expression that is expected to evaluate to non-zero at compile-time. |
#define COMPILER_FENCE |
prevent the compiler from reordering loads or stores across this point.
#define DECORATED_NAME | ( | name | ) | name |
#define EXTERN_C extern |
#define FALLTHROUGH |
#define HAVE_ASSUME_UNREACHABLE 1 |
#define HAVE_ASSUME_UNREACHABLE 0 |
#define INLINE inline |
#define MOVABLE | ( | className | ) |
Indicates that move semantics can be used, so that a NONCOPYABLE class can still be assigned by taking over the reference to the value.
Make sure to use the macro with the necessary access modifier.
#define NODEFAULT default: UNREACHABLE |
convenient specialization of UNREACHABLE for switch statements whose default can never be reached.
example usage: int x; switch(x % 2) { case 0: break; case 1: break; NODEFAULT; }
#define NONCOPYABLE | ( | className | ) |
Indicates that a class is noncopyable (usually due to const or reference members, or because the class works as a singleton).
For example:
This is preferable to inheritance from boost::noncopyable because it avoids ICC 11 W4 warnings about non-virtual dtors and suppression of the copy assignment operator.
#define NOTHROW_DECLARE |
indicate a function will not throw any synchronous exceptions, thus hopefully generating smaller and more efficient code.
must be placed BEFORE return types because "The [VC++] compiler ignores, without warning, any __declspec keywords placed after *". such syntax is apparently also legal in GCC, per the example "__attribute__((noreturn)) void d0 (void)".
example: NOTHROW_DECLARE void function(); NOTHROW_DEFINE void function() {}
#define NOTHROW_DEFINE |
#define PASTE3__ | ( | a, | |
b, | |||
c | |||
) | PASTE3_HIDDEN__(a, b, c) |
#define PASTE3_HIDDEN__ | ( | a, | |
b, | |||
c | |||
) | a ## b ## c |
#define PRINTF_ARGS | ( | fmtpos | ) |
#define RESTRICT |
#define SENTINEL_ARG |
#define STRINGIZE | ( | id | ) | STRINGIZE2(id) |
#define STRINGIZE2 | ( | id | ) | # id |
#define UID2__ PASTE3__(LINE_, __LINE__, _2) |
#define UID__ PASTE3__(LINE_, __LINE__, _) |
#define UNREACHABLE |
"unreachable code" helpers
unreachable lines of code are often the source or symptom of subtle bugs. they are flagged by compiler warnings; however, the opposite problem - erroneously reaching certain spots (e.g. due to missing return statement) is worse and not detected automatically.
to defend against this, the programmer can annotate their code to indicate to humans that a particular spot should never be reached. however, that isn't much help; better is a sentinel that raises an error if if it is actually reached. hence, the UNREACHABLE macro.
ironically, if the code guarded by UNREACHABLE works as it should, compilers may flag the macro's code as unreachable. this would distract from genuine warnings, which is unacceptable.
even worse, compilers differ in their code checking: GCC only complains if non-void functions end without returning a value (i.e. missing return statement), while VC checks if lines are unreachable (e.g. if they are preceded by a return on all paths).
the implementation below enables optimization and automated checking without raising warnings.
#define UNREACHABLE |
"unreachable code" helpers
unreachable lines of code are often the source or symptom of subtle bugs. they are flagged by compiler warnings; however, the opposite problem - erroneously reaching certain spots (e.g. due to missing return statement) is worse and not detected automatically.
to defend against this, the programmer can annotate their code to indicate to humans that a particular spot should never be reached. however, that isn't much help; better is a sentinel that raises an error if if it is actually reached. hence, the UNREACHABLE macro.
ironically, if the code guarded by UNREACHABLE works as it should, compilers may flag the macro's code as unreachable. this would distract from genuine warnings, which is unacceptable.
even worse, compilers differ in their code checking: GCC only complains if non-void functions end without returning a value (i.e. missing return statement), while VC checks if lines are unreachable (e.g. if they are preceded by a return on all paths).
the implementation below enables optimization and automated checking without raising warnings.
#define UNUSED | ( | param | ) |
mark a function parameter as unused and avoid the corresponding compiler warning.
wrap around the parameter name, e.g. void f(int UNUSED(x))
#define UNUSED2 | ( | param | ) | ((void)(param)) |
mark a function local variable or parameter as unused and avoid the corresponding compiler warning.
note that UNUSED is not applicable to variable definitions that involve initialization, nor is it sufficient in cases where an argument is unused only in certain situations. example: void f(int x) { ASSERT(x == 0); UNUSED2(x); } this asserts in debug builds and avoids warnings in release.
#define VPRINTF_ARGS | ( | fmtpos | ) |
#define VWPRINTF_ARGS | ( | fmtpos | ) |
#define WIDEN | ( | x | ) | WIDEN2(x) |
#define WIDEN2 | ( | x | ) | L ## x |
#define WPRINTF_ARGS | ( | fmtpos | ) |
Silence the 'unused result' warning.
(void) would be sufficient but Spidermonkey still uses warn_unused_result, and GCC is stricter about that. See https://bugzilla.mozilla.org/show_bug.cgi?id=1571631.