|
CX Framework
Cross-platform C utility framework
|
Cross-platform macros for controlling code generation and memory layout. These macros provide a consistent interface across compilers for common optimizations and attributes.
Allocate memory on the stack (equivalent to alloca).
Allocates the specified number of bytes on the current stack frame. The memory is automatically freed when the function returns. This is faster than heap allocation but should be used carefully as it can cause stack overflow if used with large or unbounded sizes.
Warning: The allocated memory is only valid until the function returns. Do not return pointers to stack-allocated memory.
| sz | Number of bytes to allocate |
Example:
Force a function to be inlined.
Apply to functions that are critical to performance or used for metaprogramming where inlining is essential for proper code generation. The compiler will aggressively inline these functions even at low optimization levels.
Note: Despite the leading underscore, this macro is part of the public API. It's prefixed with underscore to match C11 conventions and avoid conflicts with user code.
Example:
Prevent a function from being inlined.
Apply to functions where inlining would be detrimental (e.g., rarely called error handlers, functions with large bodies, or when you need a stable function address for debugging).
Example:
Indicate that a function never returns to its caller.
Apply to functions that always exit the program, throw exceptions, or perform long jumps. This helps the compiler optimize code paths and eliminates warnings about missing return statements in calling code.
Example:
Align a variable or struct to a specific byte boundary.
Ensures that the declared variable or type is aligned to the specified power-of-2 byte boundary. This is useful for SIMD operations, cache line alignment, or interfacing with hardware that requires specific alignment.
| bytes | Alignment in bytes (must be power of 2) |
Example: