Overview

Macros refer to #define directives that specify terms that should be textually replaced by the preprocessor during compilation:

#define NAME ...

For types that don’t have literals that describe their constants, we can use compound literals on the replacement side of the macro:

#define NAME (T){ INIT }

Operators

The # operator is used to stringify an argument. For example, calling foo(bar) in the following yields "bar".

#define foo(T) #T

The ## operator is used to concatenate tokens. For example, calling foo(bar) in the following yields bar_init.

#define foo(T) T ## _init

Variable Argument Lists

The construct ... provides an argument list of variable length. This set of arguments is then accessible inside the macro expansion as __VA_ARGS__.

Bibliography

  • Jens Gustedt, Modern C (Shelter Island, NY: Manning Publications Co, 2020).