C代码宏:#如果检查等式 [英] C macro: #if check for equality

查看:98
本文介绍了C代码宏:#如果检查等式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法做到为您在宏数值平等?

Is there a way to do check for numerical equality in macros?

我想要做这样的事情。

#define choice 3

#if choice == 3
  ....
#endif

#if choice == 4
 ...
#endif

请问C宏有这样的事情支持吗?

Does C macros have support for things like this?

推荐答案

事实上,应该工作。请参见 http://gcc.gnu.org/onlinedocs/cpp/If.html#如果

Indeed that should work. See http://gcc.gnu.org/onlinedocs/cpp/If.html#If

这是参考可能是准确的,但写成标准格式 - 抽象而不例子。我很高兴,我发现这个简单的问题和响应,当我有同样的问题。

That reference is probably accurate, but written in "standards format" -- abstractly without examples. I'm glad I found this simple question and response when I had the same issue.

这篇关于C代码宏:#如果检查等式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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