No.
In C++, this:
x == a || b // Same as (x == a) || b
Is equivalent to this:
(x == a) || (bool)b
Which evaluates to true
if x
and a
are equal OR if b
evaluates to true
when converted to bool
. In C, on the other hand, it is equivalent to this:
(x == a) || (b != 0)
Which evaluate to true
if x
and a
are equal OR if b
is different from 0 (here we must make the implicit assumption that b
is of integral type, otherwise this won't compile).
On the other hand, this:
(x == a || x == b) // Same as ((x == a) || (x == b))
Evaluates to true
when either x
and a
are equal OR x
and b
are equal (i.e., if x
is either equal to a
or equal to b
) both in C++ and in C.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…