6.5.7 Bitwise shift operators

Previous Table of Contents

1171

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

1172 Each of the operands shall have integer type.

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

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

1175 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.

1176 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.

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

1178 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.

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

1180 vacated bits are filled with zeros.

1181 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.

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

1183 otherwise, the behavior is undefined.

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

1185 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.

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

Next

Created at: 2005-06-29 02:19:00 The text from WG14/N1124 is copyright © ISO