Man, y'all really started a firestorm here at MW....:-)
After a small spirited discussion, it looks like it is not a bug after all.
Given an expression like:
return x + (signed long) (y - z) * 10;
ANSI 6.3.3:
"Except as indicated by the syntax or otherwise specified later (for the
function-call operator (), &&, ||, ?: and comma operators) the order of
evaluation of subexpressions and the order in which side effects take place
are both unspecified"
Footnote 57:
"This paragraph renders undefined statement expressions such as
i = ++i + 1;
while allowing
i = i + 1;"
So the result of the above expression is undefined.
Hope this helps.
Jun-Kiat Lam
Metrowerks Technical Support
----- Original Message -----
From: "Nathan J. Williams" <[EMAIL PROTECTED]>
To: "Palm Developer Forum" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Wednesday, February 16, 2000 9:40 PM
Subject: Re: CW6 optimizer bug?
> Marshall Clow <[EMAIL PROTECTED]> writes:
>
> > >Not quite. The conversion from unsigned to signed int *is*
well-defined.
> >
> > For some implementations.
>
> For any implementation that conforms to ANSI. Random non-conforming
> implementations are out of scope.
>
> >
> >
> > >Chapter and verse: ANSI, 3.2.1.2, lines 23-27:
> ...
> >
> > And if the unsigned integer does not have greater size?
>
> Next paragraph:
>
> "When a value with integral type is demoted to an unsigned integer
> with smaller size, the result is the nonnegative remainder on division
> by the number one greater than the largest unsigned number that can be
> represented in the type with the smaller size."
>
> > >So an expression like "(unsigned int) 1 + -10" is officially
> > >well-defined and has the value UINT_MAX - 8.
> >
> > Assuming two's-complement representation.
>
> No, see what I wrote before. The spec requires the behaviour of
> two's-complement representation even for systems with other underlying
> representations. From the Rationale for the same section:
>
> "Precise rules are now provided for converting to and from
> unsigned integers. On a twos-complement machine, the operation is
> still virtual (no change of representation is required), but the
> rules are now stated inependent of representation."
>
> - Nathan
>
> --
> For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palm.com/devzone/mailinglists.html
>
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palm.com/devzone/mailinglists.html