xylophone21
2015-05-22 19:33:00 +08:00
只读了第一个字节,并没有读第二个字节。这个怎么解释?
0x12 0x34 ==> 0x1200? 0x0034? 0x3412?
1. *(p->pointer++) << 8 溢出?
2. C规范定义中没有说|操作的左右顺序,但也没有说行为是未定义的。不过讲||时,它用了一个unlike,这种东西跟优先级差不多,虽然有规则,但没几个人记得住,用()规避的好。
6.5.12 Bitwise inclusive OR operator
Syntax
1 inclusive-OR-expression: exclusive-OR-expression
inclusive-OR-expression | exclusive-OR-expression
Constraints
2 Each of the operands shall have integer type.
Semantics
3 The usual arithmetic conversions are performed on the operands.
4 The result of the | operator is the bitwise inclusive OR of the operands (that is, each bit in the result is set if and only if at least one of the corresponding bits in the converted operands is set).
6.5.14 Logical OR operator
Syntax
1 logical-OR-expression: logical-AND-expression
logical-OR-expression || logical-AND-expression
Constraints
2 Each of the operands shall have scalar type.
Semantics
3 The || operator shall yield 1 if either of its operands compare unequal to 0; otherwise, it yields 0. The result has type int.
4 Unlike the bitwise | operator, the || operator guarantees left-to-right evaluation; there is a sequence point after the evaluation of the first operand. If the first operand compares unequal to 0, the second operand is not evaluated.