Stefan said:
Before the comparision takes place, the values will
be converted to have the same type. I need to understand
more about this conversion to be able to see whether this
comparision has the intended behavior. So, to which type
will the operands be converted, and what could this mean
for the comparision semantics?
(From earlier posts, `l' is of type ptrdiff_t, and has
already been found to be non-negative.)
If PTRDIFF_MAX < UINT_MAX, the value of `l' is converted
to unsigned int before the comparison. Conversion from a
signed to an unsigned type necessarily alters the value of a
negative number, but we already know `l >= 0' so this is not
an issue. Also, since the value of `l' is within the range
of unsigned int, there's no truncation to worry about. The
comparison takes place without surprises.
If PTRDIFF_MAX > UINT_MAX, the value of UINT_MAX is
converted to ptrdiff_t before the comparison. Since the
value of UINT_MAX is within the range of ptrdiff_t, there is
no out-of-range condition in the conversion, and UINT_MAX
survives the conversion with its value unscathed. Again, the
comparison produces no surprises.
If PTRDIFF_MAX == UINT_MAX (I'm not sure this is possible,
but padding bits can, in theory, produce many oddities), we
don't know which value is converted to the other's type, but
we know that it survives unchanged. Once again, the comparison
fails to startle anyone.