Integer promotion, relational operators, and unequal integer ranks.

Integer promotion, relational operators, and unequal integer ranks.

Post by charles_ge » Wed, 17 Jan 2007 05:31:19


i all,

I had a question about the topics in the subject and posted to
comp.std.c, but feel it may also be appropriate here. Please excuse
this crosspost if it is in bad form.

I have a question about whether or not I am interpreting a nuance of
the standard correctly, and the implications of said nuance. The
sections in the C99 standard (and possibly older standards) that I will
reference are as follows (typed out hopefully to avoid people having to
flip through their own manuals; if you want to fast forward to the meat
of this post, skip down to "-------end reference-------" line):

-------begin reference-------
6.2.6.2p2 (specifically):

For signed integer types, the bits of the object representation shall
be divided into three groups: value bits, padding bits, and the sign
bit. There need not be any padding bits; there shall be exactly one
sign bit. 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)...

6.3.1.1p1:

Every integer type has an integer conversion rank defined as follows:

o two signed integer types shall have the same rank, even if they
have the same representation.
he rank of a signed integer type shall be greater than the rank of
any signed integer type with less precision.
he rank of long long int shall be greater than the rank of long
int, which shall be greater than the rank of int, which shall be
greater than the rank of short int, which shall be greater than the
rank of signed char.
he rank of any unsigned integer type shall equal the rank of the
corresponding signed integer type, if any.
he rank of any standard integer type shall be greater than the rank
of any extended integer type with the same width.
he rank of char shall equal the rank of signed char and unsigned
char.
he rank of_Bool shall be less than the rank of all other standard
integer types.
he rank of any enumerated type shall equal the rank of the
compatible integer type (see 6.7.2.2).
he rank of any extended signed integer type relative to another
extended signed integer type with the same precision is
implementation-defined, but still subject to the other rules for
determining the integer conversion rank.
or all integer types T1, T2, andT3, if T1 has greater rank than T2
and T2 has greater rank than T3, then T1 has greater rank than T3.

6.3.1.8p1 (specifically):

Otherwise, the integer promotions are performed on both operands. Then
the following rules are applied to the promoted operands:

If both operands have the same type, then no further conversion is
needed.

Otherwise, if both operands have signed integer types or both have
unsigned integer types, the operand with the type of lesser integer
conversion rank is converted to the type of the operand with greater
rank.

Otherwise, if the operand that has unsigned integer type has rank
greater or equal to the rank of the type of the other operand, then the
operand with signed integer type is converted to the type of the
operand with unsigned
integer type.

Otherwise, if the type of the operand with signed integer type can
represent all of the values of the type of the operand with unsigned
integer type, then the operand with unsigned integer type is converted
to the type of the
operand with signed integer type.

Otherwise, both operands are converted to
 
 
 

Integer promotion, relational operators, and unequal integer ranks.

Post by christian. » Wed, 17 Jan 2007 08:21:57


You better recheck this, but


which means that SIZE_MAX will be at least promoted to unsigned int.