6.2.6.2 Integer types

Previous Table of Contents "New C Standard" commentary

593 For unsigned integer types other than unsigned char, the bits of the object representation shall be divided into two groups: value bits and padding bits (there need not be any of the latter).

594 If there are N value bits, each bit shall represent a different power of 2 between 1 and 2N-1, so that objects of that type shall be capable of representing values from 0 to 2N−1 using a pure binary representation;

595 this shall be known as the value representation.

596 The values of any padding bits are unspecified.44)

597 For signed integer types, the bits of the object representation shall be divided into three groups: value bits, padding bits, and the sign bit.

598 There need not be any padding bits;

599 there shall be exactly one sign bit.

600 Each bit that is a value bit shall have the same value as the same bit in the object representation of the corresponding unsigned type (if there are M value bits in the signed type and N in the unsigned type, then M ≤ N).

601 42)Thus, for example, structure assignment may be implemented element-at-a-time or via memcpy. need not copy any padding bits.

602 43) It is possible for objects x and y with the same effective type T to have the same value when they are accessed as objects of type T, but to have different values in other contexts.

603 In particular, if == is defined for type T, then x == y does not imply that memcmp(&x, &y, sizeof (T)) == 0.

604 Furthermore, x == y does not necessarily imply that x and y have the same value;

605 other operations on values of type T may distinguish between them.

606 44) Some combinations of padding bits might generate trap representations, for example, if one padding bit is a parity bit.

607 Regardless, no arithmetic operation on valid values can generate a trap representation other than as part of an exceptional condition such as an overflow, and this cannot occur with unsigned types.

608 All other combinations of padding bits are alternative object representations of the value specified by the value bits.

609 If the sign bit is zero, it shall not affect the resulting value.

610 If the sign bit is one, the value shall be modified in one of the following ways:

611 —  the corresponding value with sign bit 0 is negated (sign and magnitude);

612 —  the sign bit has the value -(2N) (two's complement);

613 —  the sign bit has the value -(2N-1) (one's complement).

614 Which of these applies is implementation-defined, as is whether the value with sign bit 1 and all value bits zero (for the first two), or with sign bit and all value bits 1 (for one's complement), is a trap representation or a normal value.

615 In the case of sign and magnitude and one's complement, if this representation is a normal value it is called a negative zero.

616 If the implementation supports negative zeros, they shall be generated only by:

617 —  the &, |, ^, ~, <<, and >> operators with arguments that produce such a value;

618 —  the +, -, *, /, and % operators where one argument is a negative zero and the result is zero;

619 —  compound assignment operators based on the above cases.

620 It is unspecified whether these cases actually generate a negative zero or a normal zero, and whether a negative zero becomes a normal zero when stored in an object.

621 If the implementation does not support negative zeros, the behavior of the &, |, ^, ~, <<, and >> operators with arguments that would produce such a value is undefined.

622 The values of any padding bits are unspecified.45)

623 A valid (non-trap) object representation of a signed integer type where the sign bit is zero is a valid object representation of the corresponding unsigned type, and shall represent the same value.

624 For any integer type, the object representation where all the bits are zero shall be a representation of the value zero in that type.

625 The precision of an integer type is the number of bits it uses to represent values, excluding any sign and padding bits.

626 The width of an integer type is the same but including any sign bit;

627 thus for unsigned integer types the two values are the same, while for signed integer types the width is one greater than the precision.

628 45) Some combinations of padding bits might generate trap representations, for example, if one padding bit is a parity bit.

629 Regardless, no arithmetic operation on valid values can generate a trap representation other than as part of an exceptional condition such as an overflow.

630 All other combinations of padding bits are alternative object representations of the value specified by the value bits.

Next

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