On May 9, 10:26*pm, "Paul J. Lucas" <paul-nos...@nospam.lucasmail.org>
wrote:
Given this:
* * * * #define NUM 100
I was to use a CPP macro like:
* * * * char *p = MACRO(NUM);
and have MACRO defined such that it would expand to:
* * * * char *p = "100";
I tried:
* * * * #define MACRO(X) #X
but, for MACRO(NUM), that expands to:
* * * * char *p = "NUM";
How can I get CPP to expand NUM first?
- Paul
The preprocessor will expand the macro parameters first, unless
they appear next to a # (or ##).
So try this:
#define NUM 100
#define MACRO(X) #X
#define GOODMACRO(X) MACRO(X)
char *p=GOODMACRO(NUM);
GOODMACRO's argument is not following an #, so it is expanded, prior
to
looking at MACRO's meaning.
Szabolcs