문제

When using the #warning directive, rather than one warning I get two - the one I generate, plus an additional warning: #warning is a GCC extension [enabled by default].

I can suppress the #warning directive's result itself, with -Wno-cpp, but that's the opposite of what I want.

I can work around this by instead using #pragma message() but that seems to render the #warning directive rather pointless - is there no way to suppress this warning warning?

도움이 되었습니까?

해결책

Ah, it seems the -pedantic option enables this warning, and there does not seem to be a specific override for it, as there is with most other GCC warnings. Removing -pedantic gets rid of the warning about a warning.

다른 팁

#ifdef __GNUC__
#warning "no warning here!"
#endif

will compile with or without gcc, even with -pedantic, but it will still give the warning, (and fail if warnings are escalated to errors).

UPDATE: According to this related question, there is no clean solution to selectively disable the warnings about the gnu-specific #pragma s

Actually, the following should work. With that you can suppress/ignore the gcc warnings.

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcpp"

...

#pragma GCC diagnostic pop
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top