How can I merge two X-Macros together?

215 views Asked by At

I have a lot of repetitive code that needs me to use different sets of data frequently in some function or some operation. i.e as shown below (the numbers and letters are just place holders, all i need to do is string two sets of data together using x macros)

a = 1
a = 2
a = 3
a = 4
.
.
.

then

b = 1
b = 2
b = 3
.
.
.

and

c = 1
c = 2
c = 3
.
.
.

I was trying to create an X-macro that combines the following two X-macros into one

//X-macro 1
#define SET_1 \
X(a) \
X(b) \
X(c) \
//X-macro 2
#define SET_2 \
X(1) \
X(2) \
X(3) \
X(4) 

Any help?

1

There are 1 answers

2
chqrlie On

How about this approach:

#define X_abc(X,X2) \
X(a,X2) \
X(b,X2) \
X(c,X2)

#define X_1234(x,X2) \
X2(x,1) \
X2(x,2) \
X2(x,3) \
X2(x,4) 

#define SET(x,y)     x = y;
#define DEFINE(x,y)  int x = y;

X_abc(X_1234,DEFINE)