|Doc No:||WG14 N1348|
|Reply to:||Bill Seymour <email@example.com>|
For example, with predefined macros:
#ifdef __STDC_HAS_FOO__ // a new predefined macro for each header #include <foo.h> // ... #else // ... #endif
Or if we don’t mind adding a
#if available(<foo.h>) // or just overload defined() itself #include <foo.h> // ... #else // ... #endif
#if include(<foo.h>) // tries to #include <foo.h> // ... #else // ... #endif
This can also be seen as a C++ compatibility issue because some C++0X implementors might well want to support some C1X features as extensions, just as some C++98 implementors did in fact support some of C99. Indeed, this paper was triggered because of the author’s desire to use <stdint.h> types, if available, in C++ code.
And note that this might also be useful in freestanding implementations that support some, but not all, of the standard headers required for hosted implementations (for example, <errno.h> but not <stdio.h>).
Feature-test macros in the headers are clearly no help with this particular problem because you have to include the header to get the macro; and __STDC_VERSION__ isn’t a clue unless the implementation is fully conforming. (For example, some version of gcc might have what I want; but it can’t set __STDC_VERSION__ to the required value because it doesn’t have everything yet.)
Solving this problem today requires either having different versions of your code for different implementations or testing version numbers for every possible implementation of the standard library to which you might want to port your code. (For an example of the latter in C++, have a look at all the hoops that Boost jumps through.)
The author believes that either new predefined feature-test macros or a small change to the preprocessor would be a big help to users who need to support implementations conforming to different versions of the Standard.