libcute 0.1
Loading...
Searching...
No Matches
Macros
macro.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define CU_IF_NULL(expr)   if ((expr) == NULL)
 
#define CU_IF_NOT_NULL(expr)   if ((expr) != NULL)
 
#define CU_DIE(msg)   cu_panic_handler("Fatal error: %s", msg)
 
#define CU_ALIGN_UP(x, align)   (((x) + (align) - 1) & ~((align) - 1))
 
#define CU_UNUSED(expr)   (void)(expr)
 
#define CU_ARRAY_LEN(arr)   (sizeof(arr) / sizeof((arr)[0]))
 
#define CU_BIT(x)   (1u << (x))
 
#define CU_CONCAT_(a, b)   a##b
 
#define CU_CONCAT(a, b)   CU_CONCAT_(a, b)
 
#define CU_MIN(a, b)   ((a) < (b) ? (a) : (b))
 
#define CU_MAX(a, b)   ((a) > (b) ? (a) : (b))
 
#define CU_PLAT_WINDOWS   0
 
#define CU_PLAT_MACOS   0
 
#define CU_PLAT_LINUX   0
 
#define CU_PLAT_WASM   0
 
#define CU_PLAT_BSD   0
 
#define CU_PLAT_POSIX   0
 
#define CU_COMPILER_CLANG   0
 
#define CU_COMPILER_GCC   0
 
#define CU_COMPILER_MSVC   0
 
#define CU_COMPILER_TCC   0
 
#define CU_COMPILER_INTEL   0
 
#define CU_COMPILER_LLVM   0
 
#define UNREACHABLE(msg)   cu_panic_handler("Unreachable code reached: %s", msg)
 
#define TODO(msg)   cu_panic_handler("TODO: %s", msg)
 
#define CU_AS(expr, T)   (T)(expr)
 

Detailed Description

Common utility macros.

Macro Definition Documentation

◆ CU_ALIGN_UP

#define CU_ALIGN_UP (   x,
  align 
)    (((x) + (align) - 1) & ~((align) - 1))

Round x up to the nearest multiple of align.

◆ CU_ARRAY_LEN

#define CU_ARRAY_LEN (   arr)    (sizeof(arr) / sizeof((arr)[0]))

Array element count.

◆ CU_BIT

#define CU_BIT (   x)    (1u << (x))

Create a bit mask with bit x set.

◆ CU_CONCAT_

#define CU_CONCAT_ (   a,
 
)    a##b

Concatenate two tokens after expanding them.

◆ CU_DIE

#define CU_DIE (   msg)    cu_panic_handler("Fatal error: %s", msg)

Abort the program with an error message.

◆ CU_IF_NOT_NULL

#define CU_IF_NOT_NULL (   expr)    if ((expr) != NULL)

Execute the following block if expr is not NULL.

◆ CU_IF_NULL

#define CU_IF_NULL (   expr)    if ((expr) == NULL)

Execute the following block if expr is NULL.

◆ CU_PLAT_WINDOWS

#define CU_PLAT_WINDOWS   0

Platform detection macros

◆ CU_UNUSED

#define CU_UNUSED (   expr)    (void)(expr)

Silence unused variable warnings.