For peternilsson42:

I was not clear and you did not read message 68798.

http://tech.groups.yahoo.com/group/c-prog/message/68798

To clarify:

That code I compiled on two independent compilers. On both compilers:

USHRT_MAX is 0xffff
UINT_MAX is 0xffffffff
ULLONG_MAX is 0xffffffffffffffff

> For integers with a 'rank' less than int, if the range of
> the integer type fits into the range of int, then that
> type will promote to int, if it is promoted. If the
> range won't fit into an int, it will be promoted to an
> unsigned int.

It shows that you read the standard.

> Consider the test: (-1 < (unsigned short) 1)
> 
> Whilst intuitively it should always be true, there are
> many implementations where it is false!

The unsigned short value 1 fits into an int and -1 is an int, so,
according to the standard this test must be true.

>>> a = -1;

I changed this line in message 68798 to:

a = USHRT_MAX;

> Here's a table of what a will promote to, and the type of
> a * a, dependant on the maximum values of unsigned short,
> int and unsigned int:

I'm sorry I was not sufficiently clear.

> Unsigned integers do not get sign-extended when promoted
> to wider unsigned integer types. Why? Because there is
> no sign to extend!

This is exactly how I thought before I saw two independent compilers
producing the binaries that result that result.

> First, you believe promotion works from the outside in.
> In other words, the type of the variable you're assigning
> to will influence the types and promotion of the expression
> on the right hand side. They won't. It works from the
> inside out.

No. I used unsigned short int and unsigned long long int because the
original calculation needs them, because the result of the original
calculation may not fit inside an unsigned int. The original
calculation is more complex than a multiplication of two integers.

> Secondly, you've probably been confused by 'hex' output

No. I used hexadecimal representation because these extreme values are
best represented in hexadecimal.

I hope that you answer my question, that is explicit in my other
message.

My personal opinion is that the two independent compilers I used are
buggy, but I want another opinion before reporting this bug to two
independent developers.


Reply via email to