0

If there is a macro that is a parameter to another macro, and that parameter is to be stringifyed in the macro definition, is it possible to stringify not the macro that is the parameter, but its original value? An example follows,

#define EXAMPLE "original"
#define CONCATENATE(X) "Concatenate Strings " #X

CONCATENATE(BYTE)  //Results as "Concatenate Strings EXAMPLE"
                   //I need "Concatenate Strings original"

Is there a way for me to stringify original value of the macro that is given as the parameter?

too honest for this site
  • 12,050
  • 4
  • 30
  • 52
nmd_07
  • 666
  • 1
  • 9
  • 25
  • May be a possible duplicate yet title of this question is directly related to a particular problem whereas the other's title is a bit more general. – nmd_07 Feb 23 '17 at 22:10

1 Answers1

1

The stringification operator suppresses macro argument expansion when producing tokens. To force it, you need to pass the argument through an intermediate macro.

For example, by making CONCATENATE a complete wrapper:

#define CONCATENATE_(X, Y) X #Y
#define CONCATENATE(X) CONCATENATE_("Concatenate Strings", X)
StoryTeller - Unslander Monica
  • 165,132
  • 21
  • 377
  • 458