[英]Is there a #define for C99?
I want to do something in C99 one way, otherwise to perform it another way. 我想以一种方式在C99中做一些事情,否则以另一种方式执行它。 What is the
#define
to check for? 要检查的
#define
是什么?
#ifdef C99
...
#else
...
#endif
There is not an specific #define
value. 没有特定的
#define
值。 Just check __STDC_VERSION__
and define it yourself! 只需检查
__STDC_VERSION__
并自行定义! ;-) ;-)
#if __STDC_VERSION__ >= 199901L
/* C99 code */
#define C99
#else
/* Not C99 code */
#endif
#ifdef C99
/*My code in C99 format*/
#else
/*My code in C99 format*/
#endif
EDIT: A more general snippet, from here . 编辑:一个更通用的片段, 从这里开始 。 I've just changed the defined names, just in case you'll use them a lot on the code:
我刚刚更改了已定义的名称,以防您在代码中大量使用它们:
#if defined(__STDC__)
# define C89
# if defined(__STDC_VERSION__)
# define C90
# if (__STDC_VERSION__ >= 199409L)
# define C94
# endif
# if (__STDC_VERSION__ >= 199901L)
# define C99
# endif
# if (__STDC_VERSION__ >= 201112L)
# define C11
# endif
# endif
#endif
#if __STDC_VERSION__ == 199901L
/* C99 */
#else
/* not C99 */
#endif
Change ==
to >=
if you want to test for C99 and later. 如果要测试C99及更高版本,请将
==
更改为>=
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.