The argument of _Pragma is a string so I would think that when you paste strings together in the normal c-preprocessor way (ie putting them right next to eachother) that you could form a new string for the argument of _Pragma. However
_Pragma("GCC Poison " "puts")
fails with the error
error: _Pragma takes a parenthesized string literal
How can this be circumvented?
This particular example isn't very useful and has a trivial solution of making them all one string to begin with, but the end goal is to stringize a macro into it
The DO_PRAGMA
macro in the GNU docs is defined like this
#define DO_PRAGMA(x) _Pragma (#x)
Using this, if you put two seperate token unstringized next to eachother, they will become stringized. To expand macros within the definition, it must go through one level of indirection, so define as
#define DO_PRAGMA_(x) _Pragma (#x)
#define DO_PRAGMA(x) DO_PRAGMA_(x)
Using this you can create shorthands for various pragmas like this
#define POISON(name) DO_PRAGMA(GCC poison name)
POISON(puts) // becomes _Pragma("GCC poison puts")
Thanks to Eugene Sh. for pointing me to the DO_PRAGMA
macro
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With