Re: ptrdiff_t maximum

On Wed, 25 Aug 2010 04:54:00 +0100, Ben Bacarisse <ben.usenet@xxxxxxxxx>

John Kelly <jak@xxxxxxxxxxxx> writes:

last = 32767;
while (last < last * 2u + 2) {
last = last * 2 + 1;

What happens if ptrdiff_t is wider than unsigned int?

The compiler must promote all operands to the largest among them. Usual arithmetic conversions

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.

That will be false, so we continue ...

Otherwise, both operands are converted to the unsigned integer type
corresponding to the type of the operand with signed integer type.

So both get converted to unsigned, equal to the size of ptrdiff_t.

Thus, it's not necessary to predetermine and force a certain size. The
compiler will handle it for you. The key is to specify 'u' so that each
operand is converted to unsigned.

Web mail, POP3, and SMTP