它是标准的#if承担不确定的符号常量为0? [英] Is it standard for #if to assume undefined symbolic constants as 0?

查看:202
本文介绍了它是标准的#if承担不确定的符号常量为0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此 C 程序

#include<stdio.h>
int main()
{

        #if UnDefinedSymbolicConstant==0
                printf("UnDefinedSymbolicConstant is equal to 0\n ");
        #else
                printf("UnDefinedSymbolicConstant is not equal to 0\n");

        #endif
        return 0;
}

UnDefinedSymbolicConstant 尚未的#define 的任何地方,它仍然被假设为0 并给出了<一个HREF =htt​​p://ideone.com/dIzNx>输出 GCC-4.3.4 为:

UnDefinedSymbolicConstant has not been #define anywhere, still it is being assumed as 0 and gives the output on gcc-4.3.4 as:

UnDefinedSymbolicConstant is equal to 0

那么,
这是标准的行为,或只在GCC是这样的吗

推荐答案

是的,这是由标准规定在6.10.1:

Yes, this is specified by the standard in 6.10.1:

由于宏扩展和定义的一元运算符替换所有已执行后,所有剩余的标识符(包括那些词法相同的关键字)被替换为PP-数0

After all replacements due to macro expansion and the defined unary operator have been performed, all remaining identifiers (including those lexically identical to keywords) are replaced with the pp-number 0

这篇关于它是标准的#if承担不确定的符号常量为0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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