The following doesn't compile:
#define SUPPRESS(w) _Pragma("GCC diagnostic ignored " ## w)
SUPPRESS("-Wuseless-cast")
int main() {
int a = (int)4;
return a;
}
Here's the error:
error: pasting ""GCC diagnostic ignored "" and ""-Wuseless-cast"" does not give a valid preprocessing token
How can I get it to work?
The thing is that
_Pragma
wants to have an escaped string-literal like soSo the trick is to add another layer of stringyfication between the call of
SUPPRESS
and the call of_Pragma
like belowSee it here in action.