在C preprocessor声明添加零 [英] Adding zero in c preprocessor statement

查看:165
本文介绍了在C preprocessor声明添加零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然通过一些C头文件(特别是 STDARG.H )看,我注意到一个非常奇特的行:

While looking through some c header files (specifically stdarg.h), I noticed a very peculiar line:

#if !defined(__STRICT_ANSI__) || __STDC_VERSION__ + 0 >= 199900L

奇怪的部分是 0 + 。零是添加剂身份;它是各种数学的人都有写空操作的。

The strange part is the + 0. Zero is the additive identity; it's one of the various math has of writing noop.

在上面的preprocessor声明的目的是什么不加零?我知道,有所有奇怪的preprocessor魔法种类的摆在那里,但是这只是似乎是可笑的。

What purpose does adding zero have in the above preprocessor statement? I know that there's all sorts of weird preprocessor magic out there, but this just seems ridiculous.

推荐答案

这如果 __ __ STDC_VERSION 定义为避免了preprocessor语法错误
空的令牌(例如,用的#define __STDC_VERSION __ )。

That avoids a preprocessor syntax error if __STDC_VERSION__ is defined as an empty token (e.g. with #define __STDC_VERSION__).

(感谢延Gustedt您指出我的回答的第一个版本是错误的。)

(Thanks to Jens Gustedt for pointing out that the first version of my answer was wrong.)

这篇关于在C preprocessor声明添加零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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