-
Notifications
You must be signed in to change notification settings - Fork 3
Standards
Bjorn Reese edited this page Jul 29, 2012
·
13 revisions
Language standards requires the existence of pre-defined macros.
| Name | Macro | Standard |
|---|---|---|
| C89 | __STDC__ | ANSI X3.159-1989 |
| C90 | __STDC_VERSION__ | ISO/IEC 9899:1990 |
| C94 | __STDC_VERSION__ = 199409L | ISO/IEC 9899-1:1994 |
| C99 | __STDC_VERSION__ = 199901L | ISO/IEC 9899:1999 |
| C11 | __STDC_VERSION__ = 201112L | ISO/IEC 9899:2011 |
| C++98 | __cplusplus = 199707L | ISO/IEC 14882:1998 |
| C++11 | __cplusplus = 201103L | Draft |
| C++/CLI | __cplusplus_cli = 200406L | ECMA-372 |
| DSP-C | ISO/IEC JTC1/SC22 WG14/N854 | |
| EC++ | __embedded_cplusplus | Embedded C++ |
:::c
#if defined(__STDC__)
# define PREDEF_STANDARD_C_1989
# if defined(__STDC_VERSION__)
# define PREDEF_STANDARD_C_1990
# if (__STDC_VERSION__ >= 199409L)
# define PREDEF_STANDARD_C_1994
# endif
# if (__STDC_VERSION__ >= 199901L)
# define PREDEF_STANDARD_C_1999
# endif
# endif
#endif
Please notice that not all compliant compilers provides the correct pre-defined macros. For example, Microsoft Visual C++ does not define __STDC__, or Sun Workshop 4.2 supports C94 without setting __STDC_VERSION__ to the proper value. Extra checks for such compilers must be added.
In continuation of the above example, pre-C89 compilers do not recognize certain keywords. Let the preprocessor remove those keywords for those compilers.
:::c
#if !defined(PREDEF_STANDARD_C_1989) && !defined(__cplusplus)
# define const
# define volatile
#endif