Re: ptrdiff_t maximum



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

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.


6.3.1.8 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
http://www.beewyz.com/freeaccounts.php

.



Relevant Pages

  • Re: First steps on overloading
    ... where the operand manipulation code is located, ... very many additions and changes to the language semantics. ... Allowing int + date, as well as date + int (although the former seems a bit ... compiler would reorder the operands. ...
    (comp.lang.misc)
  • Integer promotion, relational operators, and unequal integer ranks.
    ... Every integer type has an integer conversion rank defined as follows: ... any signed integer type with less precision. ... conversion rank is converted to the type of the operand with greater ...
    (comp.lang.c)
  • Re: ptrdiff_t maximum
    ... The compiler must promote all operands to the largest among them. ... the operand with signed integer type is converted to the type of the ... corresponding to the type of the operand with signed integer type. ...
    (comp.lang.c)
  • Re: First steps on overloading
    ... where the operand manipulation code is located, ... Allowing int + date, as well as date + int (although the former seems a bit ... compiler would reorder the operands. ...
    (comp.lang.misc)
  • Re: First steps on overloading
    ... where the operand manipulation code is located, ... Perhaps something like the pseudocode could be written by a programmer ... info on which the selections are made is available at compile time. ... with the compiler in the same form. ...
    (comp.lang.misc)