evaluation order

Andrew Koenig ark at alice.UUCP
Thu Sep 14 22:47:43 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 you can't.

However, you can be assured if you write it this way:

	len = strlen(buf);
	if (write(handle, buf, len) != len) do_something();

Is this so terrible?

You can even write it this way:

	if (len = strlen(buf), write(handle, buf, len) != len) do_something();

but I far prefer the previous way.
-- 
				--Andrew Koenig
				  ark at europa.att.com



More information about the Comp.lang.c mailing list