bochaltura
bochaltura

Reputation: 287

How can I use macro as one of other macro parameters list

Here is a dummy example:

#define DEFINE_STRUCTURE(Result, Structure, a, b, c)  int a;
#define MEMBER_INT(name, width)                       Int, name, width

When I'm doing

DEFINE_STRUCTURE(Result, Structure,  MEMBER_INT(b, c))

I get this warning:

warning C4003: not enough actual parameters for macro 'DEFINE_STRUCTURE'

but I expect it to expand to

DEFINE_STRUCTURE(Result, Structure,  Int, b, c)

How could I define the macros to achieve that?

Upvotes: 3

Views: 1128

Answers (1)

avakar
avakar

Reputation: 32655

You need to add one more step to the substitution process.

#define DEFINE_STRUCTURE(Result, Structure, a, b, c)  int a;
#define MEMBER_INT(name, width)                       Int, name, width

#define DEFINE_STRUCTURE2(Result, Structure, x) DEFINE_STRUCTURE(Result, Structure, x)
DEFINE_STRUCTURE2(Result, Structure,  MEMBER_INT(b, c))

Remember: on an invocation of a function-like macro, arguments are identified, then each argument is separately evaluated, then the parameters are substituted by the results of the evaluation.

Upvotes: 3

Related Questions