4

I have the following problem:

extern void func_name(const char *f); #define EXPECT(f) func_name(#f) #define foo bar void main() { EXPECT(foo); } 

So, the

EXPECT(foo); 

will be actually evaluated to

func_name("foo"); 

What I actually need is to convert 'foo' to 'bar', i.e. the code to become

func_name("bar"); 

So I kind of want to do this:

#define "foo" "bar" 

But this does not work, because macro names must be identifiers. I also tried to find a way to change the preprocessor precedence, so my macro will be replaced first, but didn't find a way.

The perfect solution will not change main() at all.

3

1 Answer 1

4
#define S(x) #x #define EXPECT(f) func_name(S(f)) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.