Menu

Macros

Cyder

Macros

Macros are the core feature of every preprocessor and TPP is no different. TPP implements keyword-style macros, function-style macro and variadic macros.

As an extension to the c11 standard, TPP allows function macros, to call themselves recursively, as long as they change the call parameters. This is the core concept, that allows for macros like TPP_REPEAT from the standard library.

For variadic macros, see [VarArgs]

The following example shows a simple keyword-style macro being expanded:

foobar // Expands to [foobar]
#define foobar 42
foobar // Expands to [42]

Function style macros can be defined, by typing a ( directly after the macro name:

#define not_a_function (a) a
#define       function(a) a

not_a_function(42) // Expands to [(][a][)][ ][a][(][42][)]
function(42) // Expands to [42]

Macros defined by the user can later be undefined, using the #undef directive:
Hint: TPP includes a warning (36), when undefining a macro, that doesn't exist, but this warning is disabled by default

#define foobar 42
#undef foobar

s.a. [VarArgs]
s.a. [Bracket notation]


Related

Wiki: Base file macro
Wiki: Bracket notation
Wiki: VarArgs