Utility macros for low-level systems and general C development. More...
Macros | |
| #define | SOURCE_PATH_SIZE 0 |
| Macro to truncate the root file path. | |
| #define | __FILENAME__ ((__FILE__) + (SOURCE_PATH_SIZE)) |
| Macro to adjust the file path based on SOURCE_PATH_SIZE. | |
| #define | LITERAL_I64(i) |
| #define | LITERAL_U64(i) |
| #define | I8_MAX ((i8)(((u8)(~0)) >> 1)) |
| #define | I16_MAX ((i16)(((u16)(~0)) >> 1)) |
| #define | I32_MAX ((i32)(((u32)(~0)) >> 1)) |
| #define | I64_MAX ((i64)(((u64)(~0)) >> 1)) |
| #define | I8_MIN ((i8)(1 << (7))) |
| #define | I16_MIN ((i16)(1 << (15))) |
| #define | I32_MIN ((i32)(1 << (31))) |
| #define | I64_MIN ((i64)(1 << (63))) |
| #define | U8_MAX ((u8)(~0)) |
| #define | U16_MAX ((u16)(~0)) |
| #define | U32_MAX ((u32)(~0)) |
| #define | U64_MAX ((u64)(~0)) |
| #define | PRI_I8 "hhi" |
| #define | PRI_U8 "hhu" |
| #define | PRI_I16 "hi" |
| #define | PRI_U16 "hu" |
| #define | PRI_I32 "i" |
| #define | PRI_U32 "u" |
| #define | PRI_I64 "lli" |
| #define | PRI_U64 "llu" |
| #define | MAX(a, b) |
| #define | MIN(a, b) |
| #define | CLAMP(val, min, max) |
| #define | ABS(x) |
| #define | DIFF(a, b) |
| #define | SWAP(a, b) |
| #define | PI 3.14159265358979323846 |
| #define | DEG2RAD(deg) |
| #define | RAD2DEG(rad) |
| #define | IS_NAN(x) |
| #define | FLOAT_EPSILON (1e-6f) |
| #define | DOUBLE_EPSILON (1e-12) |
| #define | ROUND(x) |
| #define | FLOOR(x) |
| #define | CEIL(x) |
| #define | FLOAT_ABS(x) |
| #define | FLOAT_ALMOST_EQUALS(x, y) |
| #define | DOUBLE_ALMOST_EQUALS(x, y) |
| #define | FLOAT_RELATIVE_EQUAL(x, y) |
| #define | DOUBLE_RELATIVE_EQUAL(x, y) |
| #define | BIT(x) |
| #define | SETBIT(x, p) |
| #define | CLEARBIT(x, p) |
| #define | GETBIT(x, p) |
| #define | TOGGLEBIT(x, p) |
| #define | __STR(s) |
| #define | STR(s) |
| #define | GLUE(a, b) |
| #define | UNIQUE_TOKEN(name) |
| #define | FOREVER for (;;) |
| #define | RANGE(begin, end) |
| #define | RANGE_STEP(begin, end, step) |
| #define | TRY_GOTO(pred, label) |
| #define | TRY_THROW(pred) |
| #define | TRY_LOG(pred, msg) |
| #define | TRY_EXEC(pred, block) |
| #define | DEFER(head, tail) |
Run tail after head in a single lexical scope (cleanup emulation). | |
| #define | STMT(stuff) |
| Multi-statement macro wrapper. | |
| #define | SCOPE(block) |
Same as STMT but uses {} explicitly. | |
| #define | ONCE(stmts) |
Execute stmts once, ever. | |
Typedefs | |
| typedef signed char | i8 |
| 8-bit signed integer | |
| typedef unsigned char | u8 |
| 8-bit unsigned integer | |
| typedef signed short int | i16 |
| 16-bit signed integer | |
| typedef unsigned short int | u16 |
| 16-bit unsigned integer | |
| typedef signed int | i32 |
| 32-bit signed integer | |
| typedef unsigned int | u32 |
| 32-bit unsigned integer | |
| typedef signed long long int | i64 |
| 64-bit signed integer | |
| typedef unsigned long long int | u64 |
| 64-bit unsigned integer | |
| typedef float | f32 |
| 32-bit float | |
| typedef double | f64 |
| 64-bit float | |
| typedef long double | f80 |
| Extended precision float (usually 80-bit) | |
| typedef __float128 | f128 |
| 128-bit float (GCC 4.3+ extension) | |
Utility macros for low-level systems and general C development.
This header provides a collection of utility macros for:
| #define __FILENAME__ ((__FILE__) + (SOURCE_PATH_SIZE)) |
Macro to adjust the file path based on SOURCE_PATH_SIZE.
This macro modifies the __FILE__ macro to remove a specified number of characters from the beginning, making the logged file paths more readable.
| #define DEFER | ( | head, | |
| tail ) |
Run tail after head in a single lexical scope (cleanup emulation).
Example usage:
continue instead of break when the scope need to be exited before (in error checking context)| #define ONCE | ( | stmts | ) |
Execute stmts once, ever.
Example usage:
| #define SCOPE | ( | block | ) |
Same as STMT but uses {} explicitly.
| #define SOURCE_PATH_SIZE 0 |
Macro to truncate the root file path.
This macro is useful when the project is compiled with CMake, allowing for a cleaner file path in logs by removing a fixed number of characters from the start of the __FILE__ macro. The default value if the macro wasn't defined earlier is 0.
| #define STMT | ( | stuff | ) |
Multi-statement macro wrapper.