Is there a preprocessor macro to detect C99 across platforms?

爱⌒轻易说出口 提交于 2019-12-05 18:04:09

问题


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.


回答1:


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



回答2:


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 constant 201ymmL.

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 as 199901L in ISO/IEC 9899:1999. The intention is that this will remain an integer constant of type long int that is increased with each revision of this International Standard.



来源:https://stackoverflow.com/questions/19674401/is-there-a-preprocessor-macro-to-detect-c99-across-platforms

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