6.5.7 Bitwise shift operators

Previous Table of Contents "New C Standard" commentary


                shift-expression << additive-expression
                shift-expression >> additive-expression

1182 Each of the operands shall have integer type.

1183 The integer promotions are performed on each of the operands.

1184 The type of the result is that of the promoted left operand.

1185 If the value of the right operand is negative or is greater than or equal to the width of the promoted left operand, the behavior is undefined.

1186 89) Another way to approach pointer arithmetic is first to convert the pointer(s) to character pointer(s): In this scheme the integer expression added to or subtracted from the converted pointer is first multiplied by the size of the object originally pointed to, and the resulting pointer is converted back to the original type.

1187 For pointer subtraction, the result of the difference between the character pointers is similarly divided by the size of the object originally pointed to.

1188 When viewed in this way, an implementation need only provide one extra byte (which may overlap another object in the program) just after the end of the object in order to satisfy the “one past the last element” requirements.

1189 The result of E1 << E2 is E1 left-shifted E2 bit positions;

1190 vacated bits are filled with zeros.

1191 If E1 has an unsigned type, the value of the result is E1 × 2E2, reduced modulo one more than the maximum value representable in the result type.

1192 If E1 has a signed type and nonnegative value, and E1 × 2E2 is representable in the result type, then that is the resulting value;

1193 otherwise, the behavior is undefined.

1194 The result of E1 >> E2 is E1 right-shifted E2 bit positions.

1195 If E1 has an unsigned type or if E1 has a signed type and a nonnegative value, the value of the result is the integral part of the quotient of E1 / 2E2.

1196 If E1 has a signed type and a negative value, the resulting value is implementation-defined.


Created at: 2008-01-30 02:39:43 The text from WG14/N1256 is copyright © ISO