Mudit Khetan wrote:
>
> Old Wolf wrote:
[...]
> > Also on the same day: icc_check is a function that returns a
> > status value, and also 'returns' the previous status value by writing
> > to the pointer you pass to it.
> >
> > if ( icc_check(&state) != state )
> > {
> > /* note that state has changed */
> > }
[...]
> 2) The condition will always be true, as function calls are resolved
> first then the result (return) of this call will be compared against
> the "state" var that has been changed by the function.
Untrue. There is no guarantee that the value of the right-hand side
of the "!=" condition isn't evaluated first, as in this pseudo-asm
code:
load R10,state
push &state
call icc_check ; (return value is stored in R0)
compare R0,R10
(ObNitPickerAvoidance: the compiler knows enough to preserve any
registers R10-R31 that it uses, so R10 won't change even if it is
used by icc_check.)
As I recall, the function call is a sequence point, but there is
no guarantee as to the order in which the statement is evaluated.
However, I'm not sure if this example invokes UB or is simply
"implementation defined".
--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody |
www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net |
www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <private.php?do=newpm&u=>