Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I implement a macro that creates a quoted string for _Pragma?

I want to have a macro that's invoked like this:

GCC_WARNING(-Wuninitialized)

which expands to code like this:

_Pragma("GCC diagnostic ignored \"-Wuninitialized\"")

I'm not having luck getting this to work, as the usual tricks of preprocessor joins and stringifying don't seem to apply or I don't know how to apply them here.

like image 705
ThreeBit Avatar asked Jan 04 '12 09:01

ThreeBit


1 Answers

With the little help of preprocessor magic:

#define HELPER0(x) #x
#define HELPER1(x) HELPER0(GCC diagnostic ignored x)
#define HELPER2(y) HELPER1(#y)
#define GCC_WARNING(x) _Pragma(HELPER2(x))

GCC_WARNING(-Wuninitialized)
like image 126
Lindydancer Avatar answered Nov 15 '22 07:11

Lindydancer