![]() The list entries could contain multiple arguments, but here only the name of the variable is used. This example defines a list of variables, and automatically generates their declarations and a function to print them out.įirst the list definition. The invocation of LIST expands X for each element in the list. Each expansion of LIST is preceded by a definition of X with the syntax for a list element. The list is defined by a macro or header file (named, LIST) which generates no code by itself, but merely consists of a sequence of invocations of a macro (classically named " X") with the elements' data. Expansion(s) of the list to generate fragments of declarations or statements.Many C programs define a macro min, for minimum, like this. Implementation Īn X macro application consists of two parts: When a macro is called with arguments, the arguments are substituted into the macro body. ![]() It remains useful also in modern-day C and C++ programming languages, but remains relatively unknown. Usage of X macros dates back to the 1960s. They are most useful where at least some of the lists cannot be composed by indexing, such as compile time.Įxamples 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. X macros are a technique for reliable maintenance of parallel lists of code and/or data, whose corresponding items must be declared or executed in the same order.
0 Comments
Leave a Reply. |