X macro

They provide reliable maintenance of parallel lists whose corresponding items must be declared or executed in the same order.

Examples of such lists particularly include initialization of arrays, in concert with declarations of enumeration constants and function prototypes; generation of statement sequences and switch arms; etc.

This example defines a list of variables, and automatically generates their declarations and a function to print them out.

The list entries could contain multiple arguments, but here only the name of the variable is used.

Line breaks and indentation have been added for ease of reading, even though they are not actually generated by the preprocessor: This example aims to improve the readability of the X macro usage by: