#if中使用的未定义常量的值是什么? [英] What is the value of an undefined constant used in #if?

查看:134
本文介绍了#if中使用的未定义常量的值是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的预处理程序似乎假定未定义的常数为0,用于评估 #if 条件。

My preprocessor appears to assume that undefined constants are 0 for the purpose of evaluating #if conditions.

这可以依赖,或者未定义的常量给出未定义的行为?

Can this be relied upon, or do undefined constants give undefined behaviour?

推荐答案

是的,可以依赖。 C99标准规定在§6.10.1¶3:

Yes, it can be relied upon. The C99 standard specifies at §6.10.1 ¶3:


由于宏扩展和定义的一元
运算符已执行,所有剩余的标识符将替换为pp-number
0

编辑

Edit

对不起,我认为这是一个C问题;仍然,没有什么大不了,C ++标准(§16.1¶4)中的等效部分陈述:

Sorry, I thought it was a C question; still, no big deal, the equivalent section in the C++ standard (§16.1 ¶4) states:


和除了 true false 之外的所有剩余标识符和关键字执行定义的一元运算符
,用pp-number替换 0

After all replacements due to macro expansion and the defined unary operator have been performed, all remaining identifiers and keywords, except for true and false, are replaced with the pp-number 0

唯一的区别是不同的处理 true false ,在C中不需要特殊处理,而在C ++中它们有特殊的含义即使在预处理阶段。

The only difference is the different handling of true and false, which in C do not need special handling, while in C++ they have a special meaning even in the preprocessing phase.

这篇关于#if中使用的未定义常量的值是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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