Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

preprocessor and macros — concept C23

The preprocessor handles inclusion, macros, and conditional compilation before C parsing; a macro argument may be expanded more than once. Function-like macros need parentheses, unique internal names, and side-effect-free arguments.

Version: C23

Syntax

preprocessor and macros

The preprocessor handles inclusion, macros, and conditional compilation before C parsing; a macro argument may be expanded more than once. Function-like macros need parentheses, unique internal names, and side-effect-free arguments.

Use an include guard in a header, and write a function-like macro such as #define SQUARE(x) ((x) * (x)) only for side-effect-free arguments. Prefer an enum, static const, or an inline function for constants and operations needing type checking.

SQUARE(i++) modifies i twice, a comma in an argument may need extra parentheses, and # or ## changes expansion rules. Limit conditional compilation to platform features; compile every branch separately because an inactive branch is not parsed as C.

Examples

#include <stdio.h>
#define SQUARE(x) ((x) * (x))
int main(void) { printf("%d\n", SQUARE(5)); return 0; }

Result

25

The preprocessor handles inclusion, macros, and conditional compilation before C parsing; a macro argument may be expanded more than once. Function-like macros need parentheses, unique internal names, and side-effect-free arguments.

Sources