C99 有#define 吗? [英] Is there a #define for C99?

查看:43
本文介绍了C99 有#define 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以一种方式在 C99 中做某事,否则以另一种方式执行.要检查的 #define 是什么?

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

推荐答案

没有特定的 #define 值.只需检查 __STDC_VERSION__ 并自己定义!;-)

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

更一般的片段,从这里.我刚刚更改了定义的名称,以防您在代码中大量使用它们:

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

这篇关于C99 有#define 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆