cbase 1.50.0
C/C++ Static Template
Loading...
Searching...
No Matches
base_macros.h File Reference

Context detection, compiler abstractions, utility macros, and data structures. More...

#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
Include dependency graph for base_macros.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define BUILD_DEBUG   1
 Defined to 1 if compiling in Debug mode.
#define BUILD_NAME   "Debug"
 Human-readable string name of the build configuration.
#define C_STANDARD   89
 Integer representing the detected C standard version.
#define C_STANDARD_NAME   "C89/Default"
 Human-readable string of the detected C standard.
#define function   static
 File-scoped function (invisible to the linker).
#define global   static
 File-scoped global variable (invisible to the linker).
#define local_persist   static
 Function-scoped static variable (persists state across calls).
#define external   extern
 Externally linked variable or function.
#define thread_local   _Thread_local
 Declares a thread-local variable (each thread gets its own instance).
#define API_EXPORT
 Exports a symbol from a shared library (.dll / .so).
#define API_LOCAL
 Hides a symbol from a shared library (.dll / .so).
#define C_LINKAGE_BEGIN
 Opens a C linkage block for C++ compilers (Empty in C).
#define C_LINKAGE_END
 Closes a C linkage block for C++ compilers (Empty in C).
#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.
#define ALIGN_UP_POW2(x, p)
 Aligns a value UP to the nearest multiple of p (must be power of 2).
#define ALIGN_DOWN_POW2(x, p)
 Aligns a value DOWN to the nearest multiple of p (must be power of 2).
#define IS_POW2_OR_ZERO(x)
 Checks if a given integer is a power of 2 or zero.
#define IS_POW2(x)
 Checks if a given integer is a strictly positive power of 2.
#define SHIFT8(T, x, s)
 Shifts a byte value to a specific bit position.
#define PACK_U32_LE(a, b, c, d)
 Packs 4 bytes into a 32-bit unsigned integer (little-endian order).
#define MEM_ZERO(ptr, size)
 Zeroes a block of memory. Wraps memset.
#define MEM_ZERO_STRUCT(ptr)
 Zeroes an entire struct via its pointer.
#define MEM_ZERO_ARRAY(arr)
 Zeroes an entire static array.
#define MEM_COPY(dst, src, size)
 Copies memory using memmove (overlap-safe).
#define MEM_COPY_STRUCT(dst, src)
 Copies one struct into another, clamping to the smaller size.
#define MEM_COPY_ARRAY(dst, src)
 Copies one static array into another, clamping to the smaller size.
#define DLL_PUSH_BACK_NP(f, l, n, next, prev)
 Pushes a node to the back of a doubly linked list (Custom pointer names).
#define DLL_PUSH_BACK(f, l, n)
 Pushes a node to the back of a doubly linked list.
#define DLL_PUSH_FRONT(f, l, n)
 Pushes a node to the front of a doubly linked list.
#define DLL_REMOVE_NP(f, l, n, next, prev)
 Removes a node from a doubly linked list (Custom pointer names).
#define DLL_REMOVE(f, l, n)
 Removes a node from a doubly linked list.
#define SLL_QUEUE_PUSH_N(f, l, n, next)
 Pushes a node to a singly linked queue (Custom pointer name).
#define SLL_QUEUE_PUSH(f, l, n)
 Pushes a node to the back of a singly linked queue.
#define SLL_STACK_PUSH_N(f, n, next)
 Pushes a node to the top of a singly linked stack (Custom pointer name).
#define SLL_STACK_PUSH(f, n)
 Pushes a node to the top of a singly linked stack.
#define SLL_STACK_POP_N(f, next)
 Pops a node from the top of a singly linked stack (Custom pointer name).
#define SLL_STACK_POP(f)
 Pops a node from the top of a singly linked stack.
#define debug_break()
 Triggers a crash (segfault) as a fallback breakpoint.
#define ASSERT(expr)
 Standard runtime assertion. Triggers a debug break on failure.
#define ASSERT_NOT_NULL(ptr)
 Asserts that a given pointer is not NULL.

Detailed Description

Context detection, compiler abstractions, utility macros, and data structures.

A zero-dependency header that determines the compilation context (OS, compiler, architecture, endianness, C standard) and exposes the results as simple macros. Also provides the core QoL macro library used across the entire codebase.

Context Detection
At the top of the file, predefined compiler macros are inspected to set a canonical set of COMPILER_*, OS_*, ARCH_*, ENDIAN_*, and C_STANDARD macros. This means downstream code never has to repeat the brittle #if defined(_MSC_VER) chains - it just checks #if COMPILER_MSVC or #if OS_WINDOWS.
Macro Categories

Definition in file base_macros.h.

Macro Definition Documentation

◆ BUILD_DEBUG

#define BUILD_DEBUG   1

Defined to 1 if compiling in Debug mode.

Definition at line 119 of file base_macros.h.

◆ BUILD_NAME

#define BUILD_NAME   "Debug"

Human-readable string name of the build configuration.

Definition at line 121 of file base_macros.h.

◆ C_STANDARD

#define C_STANDARD   89

Integer representing the detected C standard version.

Definition at line 161 of file base_macros.h.

◆ C_STANDARD_NAME

#define C_STANDARD_NAME   "C89/Default"

Human-readable string of the detected C standard.

Definition at line 163 of file base_macros.h.