A. Transitional code

 

C23 comes with a lot of new features, and at the beginning, we cannot expect that all compilers will catch up quickly to implement all new features. Nevertheless, many of these new and closely related features are already present in compilers as extensions. Therefore, in the sample code provided with this book at https://inria.hal.science/hal-03345464/document, we provide a header file <c23-fallback.h> meant to circumvent most of the difficulties you might encounter. It is systematically included in our examples, such that these should, in general, compile even in legacy settings. Nevertheless, some C23 features are required:

  • Digit separators such as in 0xAB’CD
  • Binary integer literals such as in 0b1010 or 0B0101
  • The new attribute syntax such as in [[deprecated]]

The first two are not easy to circumvent, so you should probably not even try to use C23-enabled code without having support for them.

For the attribute syntax, there is a feature test: __has_c_attribute. It can be used with define (or #ifdef) to test for the syntax itself and with #if and an argument to test for an individual attribute:

c23-fallback.h

 #ifndef __has_c_attribute
 # define __has_c_attribute(X) 0
 #endif

Another feature test is __has_include, which similarly can be used to test for the preprocessor feature itself and, if that is available, to test for the availability of a specific header. This can be used to