Is it possible to stringify this C macro:
#define GPIO_INT_PIN (GPIO_PORT_D|GPIO_PIN_IRQ_RISING|GPIO_PIN5)
using something like
MY_STRINGFY(GPIO_INT_PIN)
to get
"(GPIO_PORT_D|GPIO_PIN_IRQ_RISING|GPIO_PIN5)"
?
Is it possible to stringify this C macro:
#define GPIO_INT_PIN (GPIO_PORT_D|GPIO_PIN_IRQ_RISING|GPIO_PIN5)
using something like
MY_STRINGFY(GPIO_INT_PIN)
to get
"(GPIO_PORT_D|GPIO_PIN_IRQ_RISING|GPIO_PIN5)"
?
Yes it is possible. Read about stringification in GCC
cpp
documentation.I corrected my answer thanks to Wojtek Surowka's one
then use
MY_STRINGIFY(GPIO_PORT_D|GPIO_PIN_IRQ_RISING|GPIO_PIN5)
which would work much better if you use anenum
to define the constants, e.g.Of course that won't work as you want if you need
GPIO_PORT_D
to be a macro, .e.g. because it expands to some non-constant-literal expression (like a variable, or an access to a field of some global structure, etc....)As a counter-example:
is expanded to
"1|2"
not to"FOO|BAR"
, if your remove the two#define
-s forFOO
and forBAR
and replace them withyou really get the expansion
"FOO|BAR"
as you want. Check withgcc -C -E
...Also:
is expanded as
"(FOO|BAR)"
. But if you use#define
forFOO
and forBAR
you get the"(1|2)"
expansion.Maybe you could add in your own header, after including the external header defining
GPIO_PORT_D
etc... as a literal constants, something like :and then you'll get more readable stringified constants (but not exactly what you dream of).
If you have such two definitions
MY_STRINGIFY does what you want - expands its argument and adds quotes after.