|
cbase 1.50.0
C/C++ Static Template
|
Quality-of-life macros for strings, pointers, and math. More...
Macros | |
| #define | STRINGIFY_DETAIL(x) |
| Internal implementation of STRINGIFY. Do not use directly. | |
| #define | STRINGIFY(x) |
| Safely converts a macro argument into a string literal. | |
| #define | GLUE_DETAIL(x, y) |
| Internal implementation of GLUE. Do not use directly. | |
| #define | GLUE(x, y) |
| Safely concatenates two tokens into a single token. | |
| #define | INT_FROM_PTR(ptr) |
| Safely casts a pointer to a uintptr_t integer. | |
| #define | PTR_FROM_INT(type, val) |
| Safely casts a pointer-sized integer back to a typed pointer. | |
| #define | ARRAY_SIZE(arr) |
| Calculates the number of elements in a statically allocated array. | |
| #define | MIN(a, b) |
| Returns the minimum of two values (Standard C fallback). | |
| #define | MAX(a, b) |
| Returns the maximum of two values (Standard C fallback). | |
| #define | CLAMP(val, min, max) |
| Clamps a value between a minimum and a maximum (Standard C fallback). | |
| #define | SWAP(type, a, b) |
| Generic variable swap using a temporary. | |
| #define | Boolify(x) |
| Converts any scalar value to a strict 1 or 0 boolean. | |
| #define | AsciiID4(a, b, c, d) |
| Packs four ASCII characters into a single 32-bit FourCC integer. | |
| #define | ExpandAsciiID(x) |
| Expands a FourCC u32 for use in a printf "%.*s" format specifier. | |
Quality-of-life macros for strings, pointers, and math.
| #define ARRAY_SIZE | ( | arr | ) |
Calculates the number of elements in a statically allocated array.
Example:
| arr | The static array. |
Definition at line 318 of file base_macros.h.
| #define AsciiID4 | ( | a, | |
| b, | |||
| c, | |||
| d ) |
Packs four ASCII characters into a single 32-bit FourCC integer.
FourCC codes are commonly used for file format identification and chunk tags in binary formats (RIFF, IFF, etc.).
Example:
| a | 1st character (least significant byte). |
| b | 2nd character. |
| c | 3rd character. |
| d | 4th character (most significant byte). |
Definition at line 431 of file base_macros.h.
| #define Boolify | ( | x | ) |
Converts any scalar value to a strict 1 or 0 boolean.
Useful when you need a guaranteed 0/1 integer from an expression that might return any non-zero value (e.g., a pointer, a flags field).
Example:
| x | The value to evaluate. |
Definition at line 409 of file base_macros.h.
| #define CLAMP | ( | val, | |
| min, | |||
| max ) |
Clamps a value between a minimum and a maximum (Standard C fallback).
Definition at line 367 of file base_macros.h.
| #define ExpandAsciiID | ( | x | ) |
Expands a FourCC u32 for use in a printf "%.*s" format specifier.
Example:
| x | The FourCC integer to expand. |
Definition at line 445 of file base_macros.h.
| #define GLUE | ( | x, | |
| y ) |
Safely concatenates two tokens into a single token.
Double-expansion ensures macros in x or y are expanded first.
Example:
| x | The first token. |
| y | The second token. |
Definition at line 271 of file base_macros.h.
| #define GLUE_DETAIL | ( | x, | |
| y ) |
Internal implementation of GLUE. Do not use directly.
Definition at line 256 of file base_macros.h.
| #define INT_FROM_PTR | ( | ptr | ) |
Safely casts a pointer to a uintptr_t integer.
Example:
| ptr | The pointer to cast. |
Definition at line 286 of file base_macros.h.
| #define MAX | ( | a, | |
| b ) |
Returns the maximum of two values (Standard C fallback).
Definition at line 365 of file base_macros.h.
| #define MIN | ( | a, | |
| b ) |
Returns the minimum of two values (Standard C fallback).
Definition at line 363 of file base_macros.h.
| #define PTR_FROM_INT | ( | type, | |
| val ) |
Safely casts a pointer-sized integer back to a typed pointer.
Example:
| type | The type of pointer to return. |
| val | The integer memory address. |
Definition at line 301 of file base_macros.h.
| #define STRINGIFY | ( | x | ) |
Safely converts a macro argument into a string literal.
Unlike the # operator used directly, this double-expansion ensures that macro arguments are expanded before stringification.
Example:
| x | The token to stringify (macros are expanded first). |
Definition at line 253 of file base_macros.h.
| #define STRINGIFY_DETAIL | ( | x | ) |
Internal implementation of STRINGIFY. Do not use directly.
Definition at line 237 of file base_macros.h.
| #define SWAP | ( | type, | |
| a, | |||
| b ) |
Generic variable swap using a temporary.
Example:
| type | The data type of the variables being swapped. |
| a | The first variable. |
| b | The second variable. |
Definition at line 387 of file base_macros.h.