evaluation order
Henry Spencer
henry at utzoo.uucp
Fri Sep 15 02:23:16 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...
There is a sequence point at the function call, but it doesn't save you
because you don't know which operand of != gets evaluated first. In
general this sort of thing isn't very safe. Better would be:
len=strlen(buf);
if (write(handle, buf, len) != len) do_something();
Is there some reason why you can't just write it that way?
As in APL, C "one-liners" are a perverse art form, suitable for presentation
to the Obfuscated C Contest but usually inappropriate in production code.
--
V7 /bin/mail source: 554 lines.| Henry Spencer at U of Toronto Zoology
1989 X.400 specs: 2200+ pages. | uunet!attcan!utzoo!henry henry at zoo.toronto.edu
More information about the Comp.lang.c
mailing list