Preprocessor Macros
(ply-system.h)
Platform Detection
These macros can be used to implement platform-specific features.
PLY_WINDOWSDefined as 1 when compiling for Windows; otherwise undefined.
PLY_LINUXDefined as 1 when compiling for Linux or Android; otherwise undefined.
PLY_ANDROIDDefined as 1 when compiling for Android; otherwise undefined.
PLY_APPLEDefined as 1 when compiling for macOS or iOS; otherwise undefined.
PLY_MACOSDefined as 1 when compiling for macOS; otherwise undefined.
PLY_IOSDefined as 1 when compiling for iOS; otherwise undefined.
PLY_POSIXIndicates that a POSIX-compatible API is available. Defined as 1 when compiling for Linux, macOS, Android or iOS; otherwise undefined.
PLY_MINGWDefined as 1 when compiling for MinGW; otherwise undefined.
PLY_PTR_SIZEThe size of a pointer, in bytes. Defined as
4when compiling for a 32-bit architecture and8when compiling for a 64-bit architecture.
Compiler-Specific Wrappers
Wrappers around compiler-specific extensions. Mainly used to hide differences between MSVC and GCC/Clang.
PLY_NO_INLINEPrevents inline class methods from being considered as inlining candidates.
PLY_FORCE_INLINEA stronger version of C++'s
inlinekeyword.PLY_DEBUG_BREAKEmits a CPU instruction that causes the process to halt and invoke any attached debugger.
PLY_FORCE_CRASHEmits a CPU instruction that forces the process to crash immediately. Used internally by
PLY_ASSERTwhen an assertion fails.PLY_COMPILER_BARRIERPrevents the compiler from reordering adjacent memory operations. Can help ensure correct memory ordering in multithreaded code.
PLY_NO_DISCARDEquivalent to C++17's
nodiscardkeyword.
General-Purpose Macros
Plywood versions of commonly-used C++ macros.
PLY_STRINGIFYConverts its argument to a string literal.
PLY_STRINGIFY(__LINE__) // Expands to "42" on line 42.PLY_CATConcatenates two macro arguments into a single token.
PLY_CAT(foo, __LINE__) // Expands to "foo42" on line 42.PLY_UNIQUE_VARIABLECreates a unique variable name by appending the current line number as a suffix. Equivalent to
PLY_CAT(prefix, __LINE__). Used internally byPLY_ON_SCOPE_EXITand other macros.PLY_PTR_OFFSETAdds a byte offset to a pointer of any type and returns the result as
void*.PLY_OFFSET_OFReturns the byte offset of a member within a struct or class. Similar to C++'s
offsetofkeyword, but returns auptr.PLY_STATIC_ARRAY_SIZEEvaluates to the number of elements in a C-style array.
char buf[64]; PLY_STATIC_ARRAY_SIZE(buf) // Evaluates to 64.PLY_UNUSEDUsed to silence compiler warnings about unused variables, such as return values that are only used for assertion checks.
int rc = close(socket); PLY_ASSERT(rc == 0); PLY_UNUSED(rc); // Silences a compiler warning when assertions are disabled.
Assertions
Plywood assertions are extremely simple: If the condition fails, they immediately force a crash using a single CPU instruction. This is enough to see which assertion failed when a debugger is attached, including when a crash dump is loaded.
PLY_ASSERTIf the condition fails, immediately forces a crash. Only enabled when
PLY_WITH_ASSERTS=1.PLY_STATIC_ASSERTSingle-argument wrapper around C++'s
static_assertthat works with C++14 compilers.