Open In App

X-Macros in C

X-Macros are based on the property of nested macros and the ability to define macros inside other macros. X-Macros are very powerful pre-processor technique in the sense that it can create a self-maintaining and inter-dependent piece of code. When the change of one part of a program leads to a change in another part, then the code is said to be inter-dependent.

Syntax:
An X macro application consists of two parts:



The list is defined by a macro or header file (named, VARIABLES) which generates no code by itself, but merely consists of a sequence of invocations of a macro (classically named “X”) with the elements’ data. Each expansion of VARIABLES is preceded by a definition of X with the syntax for a list element. The invocation of VARIABLES expands X for each element in the list.

Implementations:



Advantages of X-Macros

Disadvantages of X-Macros

Reference: https://en.wikipedia.org/wiki/X_Macro


Article Tags :