Would it also be acceptable if the macro argument is enclosed in single quotes? If so, you can use this:
#define GCC_WARNING(x) _Pragma("GCC diagnostic ignored '" #x "'")
When you call it as GCC_WARNING(-Wuninitialized) , it expands to
_Pragma("GCC diagnostic ignored '" "-Wuninitialized" "'")
I had to use the string concatenation behavior of C ( printf("a" "b"); "'#x'" same as printf("ab"); ), since using "'#x'" in the macro would avoid the x extension.
source share