5

Say i have macro with x as string parameter #define a(x) "this is x". And if I call as a(test) , string formed should be "this is test".

3
  • 6
    #define a(x) "this is " #x Commented Dec 19, 2016 at 2:59
  • Thanks for reply.but if argument is in between the string say "this is x macro"? Commented Dec 19, 2016 at 3:09
  • 6
    #define a(x) "this is " #x " macro" Commented Dec 19, 2016 at 3:15

1 Answer 1

12

You're looking forward to create strings from macro argument and so, are looking for # operator. Within the replacement part of a function-like macro, the # symbol becomes a preprocessing operator that converts tokens into strings. So you need

#define a(x) "this is " #x

or

#define a(x) "this is " #x " in the middle."
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.