C++ and C warning preprocessor directive

C++ #warning and C #warning are preprocessor directives that emit a warning message during compilation.

These trivial examples assume that a warning should be omitted if symbol “MYFEATURE” is not defined.

#ifndef MYFEATURE
#if __cplusplus >= 202302L
#  warning "C++ compiler lacks feature"
#endif
#endif
#ifndef MYFEATURE
#if __STDC_VERSION__ >= 202311L
#  warning "C compiler lacks feature"
#endif
#endif

The #if strictly check that the compiler language support is at least the specified version. Most compilers have long-supported the #warning directive without the #if check needed. That is, the following is sufficient for most compilers:

#ifndef MYFEATURE
#warning "C++ compiler lacks feature"
#endif