Is there a #define for C99?

落爺英雄遲暮 提交于 2019-11-27 20:43:32

问题


I want to do something in C99 one way, otherwise to perform it another way. What is the #define to check for?

#ifdef C99
...
#else
...
#endif

回答1:


There is not an specific #define value. Just check __STDC_VERSION__ and define it yourself! ;-)

#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



回答2:


#if __STDC_VERSION__ == 199901L
/* C99 */
#else
/* not C99 */
#endif

Change == to >= if you want to test for C99 and later.



来源:https://stackoverflow.com/questions/2115867/is-there-a-define-for-c99

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!