evaluation order

Doug Gwyn gwyn at smoke.BRL.MIL
Thu Sep 14 21:52:24 AEST 1989


In article <9361 at attctc.Dallas.TX.US> bobc at attctc.Dallas.TX.US (Bob Calbridge) writes:
>if (write(handle, buf, len=strlen(buf)) != len) do_something();
>can I be assured that 'len' will be assigned the length of 'buf' before it
>is used on the right side of the comparison operator.

No.
Either side of != may be evaluated first, depending on the implementation.
It's best to split such multiple actions into separate statements;
you don't get any extra credit for complexity of the expression.



More information about the Comp.lang.c mailing list