martinkunev
martinkunev

Reputation: 1405

Expand macro before it is undefed

I have a macro that I define at the beginning of a header and then undef at the end. However that macro (I'll call it foo) depends on another macro (I'll call it test). I was wondering whether I can remember the value to which foo expands. My first idea was the following, which obviously doesn't work:

#define foo test
#define bar foo
#undef foo

...
bar
...

Is there a way to make so that in the end bar expands to test?

Upvotes: 0

Views: 65

Answers (1)

rici
rici

Reputation: 241911

No, you can't.

Macros are expanded only at the moment they are inserted into the programming token stream. They are not expanded in the #define preprocessing directive.

Upvotes: 1

Related Questions