c++c-preprocessorwarningsportabilitypreprocessor-directive

Portability of #warning preprocessor directive


I know that the #warning directive is not standard C/C++, but several compilers support it, including gcc/g++. But for those that don't support it, will they silently ignore it or will it result in a compile failure? In other words, can I safely use it in my project without breaking the build for compilers that don't support it?


Solution

  • It is likely that if a compiler doesn't support #warning, then it will issue an error. Unlike #pragma, there is no recommendation that the preprocessor ignore directives it doesn't understand.

    Having said that, I've used compilers on various different (reasonably common) platforms and they have all supported #warning.