Trivial use of X-macros for printfs
suggest change#include <stdio.h>
/* A list of invocations. X is defined by the code that uses the list. */
#define X_123 X(1) X(2) X(3)
#define X(val) printf("X(%d) made this print\n", val);
int main(void)
{
X_123
return 0;
}
#undef X /* so a later list can define X differently */
This example will result in the preprocessor generating the following code:
printf("X(%d) made this print\n", 1);
printf("X(%d) made this print\n", 2);
printf("X(%d) made this print\n", 3);
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents