Reputation: 3
Given the following defines :
#define foo bar
#define bar 2
#define reg_bar 4
I'm trying to create a macro that given the define foo, find the value of the define reg_bar, 4.
I tried this:
#define foo_bar(value) reg_##value
foo_bar(foo)
But it doesn't work, as it returns reg_foo.
And this
#define foo_bar(value) reg_##value
#define foo_bar_2(value) foo_bar(value)
foo_bar_2(foo)
But it still doesn't work as it returns reg_2
Is there anyway to do it, only with macro and preprocessor?
Thanks for your help :)
Upvotes: 0
Views: 48
Reputation: 241791
Sadly, no. There is no such thing as an "intermediate value". A token sequence is either expanded or not; ##
suppresses expansion, but there is nothing which suppressed "part of" the expansion.
Upvotes: 0