Bitwise operators ( ~ , & , | and ^ ) work with the bitwise representation of their advanced operands. Can such operations cause undefined behavior?
For example, the ~ operator ~ defined this way in the C standard:
6.5.3.3 Unary arithmetic operators
The result of the ~ operator is the bitwise complement of its (advanced) operand (that is, each bit as a result is set if and only if the corresponding bit in the converted operand is not specified). Entire promotions are performed in the operand, and the result is of an advanced type. If the advanced type is an unsigned type, the expression ~E equivalent to the maximum value represented in this dash minus E
On all architectures, ~0 creates a pattern bit with the sign bit set to 1 , and all value bits set to 1 . In a single-add architecture, this representation is negative zero. Could this bitmap be a trap representation?
Are there other examples of undefined behavior that include simple bitwise operators for more general architectures?
c ++ c language-lawyer bitwise-operators ones-complement
chqrlie Sep 24 '17 at 7:33 2017-09-24 07:33
source share