evaluation order

Conor P. Cahill cpcahil at virtech.UUCP
Fri Sep 15 02:19:20 AEST 1989


In article <9361 at attctc.Dallas.TX.US>, bobc at attctc.Dallas.TX.US (Bob Calbridge) writes:
> Is there any way to guarantee the order in which certain functions are
> evaluated?  By way of example, if I wanted to avoid the replication of 
> of strlen() in the following example:
> 
> if (write(handle, buf, strlen(buf)) != strlen(buf)) do_something();
> 
> by using rephrasing it like:
> 
> if (write(handle, buf, len=strlen(buf)) != len) do_something();
> 
How about 
	len = strlen(buf);
	if( write(...,len) != len)...

> 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.  I understand that

nope.

> some optimizing compilers may do some odd re-arranging and I'm worried that
> the value of 'len' before excuting this line of code may be used on the
> right side.  Is this really possible?  Are there any assurances?

There are no assurances as to the time the left or right side of the != are
evaluated, nor to the time at which the assignment takes place (unless a
sequence point has been reached).

> I know that I can try this with my compiler and some test code but would it
> be portable?

Nope.





-- 
+-----------------------------------------------------------------------+
| Conor P. Cahill     uunet!virtech!cpcahil      	703-430-9247	!
| Virtual Technologies Inc.,    P. O. Box 876,   Sterling, VA 22170     |
+-----------------------------------------------------------------------+



More information about the Comp.lang.c mailing list