Pete Becker
11/13/2008 8:15:00 PM
On 2008-11-13 14:31:50 -0500, Juha Nieminen <nospam@thanks.invalid> said:
> Michael wrote:
>> ++a*++a is undefined behaviour, the compiler can produce whatever it
>> likes. For example, it can yield 36,42,49,999,-1,segfault,or even launch
>> a rocket (if there is suitable hardware connected to it).
>
> Isn't that contradictory with the standard definition of the prefix
> operator ++, as using it is not undefined behavior?
The problem isn't with the prefix operator++. It's with combining two of them.
>
> Does the standard really explicitly state that it's undefined
> behavior, rather than saying something along the lines that the
> (numerical) result is undefined?
Yes.
> (In other words, the expression itself
> is completely valid and will produce an integer value as result. It's
> just not guaranteed what that value will be.)
The behavior is undefined.
--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)