是零(!0)编译器相关的用C逻辑否定? [英] Is logical negation of zero (!0) compiler dependent in C?

查看:164
本文介绍了是零(!0)编译器相关的用C逻辑否定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我碰到里面提到的!0的结果是编译器相关的文章。结果可以是1或FF或FFFF等

I came across an article which mentioned that the result of !0 is compiler dependent. The result can be either 1 or FF or FFFF and so on.

至于C99标准6.5.3.3一元算术运算符,

As for C99 standard 6.5.3.3 Unary arithmetic operators,

逻辑否定运算符的结果!是0,如果其操作数的值进行比较
  不等于0,1,如果它的操作数的值进行比较,等于0的结果具有int类型。
  这位前pression!E是等于(0 == E)。

The result of the logical negation operator ! is 0 if the value of its operand compares unequal to 0, 1 if the value of its operand compares equal to 0. The result has type int. The expression !E is equivalent to (0==E).

是不是真的编译器相关的?

Is it really compiler dependent?

推荐答案

看起来应用于已经回答了你自己的问题,从标准的引用它指定结果必须为0或1。

You seem to have answered you own question already, quoting from the standard where it specifies that the result must be 0 or 1.

因此​​,所有我能猜到是你问所有的C编译器是否符合这方面的标准一致。因为我还没有使用的每一个C编译器写过,我真的不能回答这个问题明确。我从来没有使用过或听说过一个,虽然产生的任何其他的价值 - 并给予这些年来,我在这里度过了挂出,在Usenet等等,它似乎的可能的,如果这样的野兽存在我可能已经听说过它。

As such, about all I can guess is that you're asking whether all C compilers conform with the standard in this respect. Since I haven't used every C compiler ever written, I can't really answer that definitively. I've never used or heard of one that produced any other value though -- and given the years I've spent hanging out here, on Usenet, etc., it seems likely that if such a beast existed I'd probably have heard of it.

编辑:这也许值得一提的是,即使在K&放大器; R1,它的具体描述生产0或1(§A.7.2):

It's probably worth noting that even in K&R1, it's specifically described as producing 0 or 1 (§A.7.2):

逻辑否定运算符的结果!是1,如果其操作数的值是0,0,如果它的操作数的值是非零。

The result of the logical negation operator ! is 1 if the value of its operand is 0, 0 if the value of its operand is non-zero.

这篇关于是零(!0)编译器相关的用C逻辑否定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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