C++ has a __cplusplus
preprocessor define that lets you detect the version. Is there anything similar for C?
Preferably I'd like it to be portable across XCode, GCC, and Visual Studio versions.
The C preprocessor is a macro preprocessor (allows you to define macros) that transforms your program before it is compiled. These transformations can be the inclusion of header files, macro expansions, etc.
Preporcessor: the program that does the preprocessing (file inclusion, macro expansion, conditional compilation). Macro: a word defined by the #define preprocessor directive that evaluates to some other expression. Preprocessor directive: a special #-keyword, recognized by the preprocessor.
Macro expansion overviewThe preprocessor maintains a context stack, implemented as a linked list of cpp_context structures, which together represent the macro expansion state at any one time. The struct cpp_reader member variable context points to the current top of this stack.
The #ifndef directive checks for the opposite of the condition checked by #ifdef . If the identifier hasn't been defined, or if its definition has been removed with #undef , the condition is true (nonzero). Otherwise, the condition is false (0). The identifier can be passed from the command line using the /D option.
As per article on Wikipedia on C99
A standard macro __STDC_VERSION__ is defined with value 199901L to indicate that C99 support is available
#if __STDC_VERSION__ >= 199901L
/*C99*/
#else
/*Not C99*/
#endif
You can test the value of the macro __STDC_VERSION__
(note there are two underscores in the beginning and in the end), it should be larger than or equal to 199901L
for C99 compatible platforms.
C11(ISO/IEC 9899:201x) §6.10.8.1 Mandatory macros
__STDC_VERSION__
The integer constant201ymmL
.
In the footnote:
This macro was not specified in ISO/IEC 9899:1990 and was specified as
199409L
in ISO/IEC 9899/AMD1:1995 and as199901L
in ISO/IEC 9899:1999. The intention is that this will remain an integer constant of typelong int
that is increased with each revision of this International Standard.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With