evaluation order

Jeff Rosenfeld jdr+ at andrew.cmu.edu
Thu Sep 14 22:28:51 AEST 1989


> Excerpts from netnews.comp.lang.c: 14-Sep-89 evaluation order Bob
> Calbridge at attctc.Dal (1134)

> 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();


What's wrong with
	len = strlen(buf);
	if (write(handle,buf,len) != len) do_something();
?

Just because C lets you do funky things doesn't mean that you have to do
them all the time. If you really want to do it in one statement you can:

	len=strlen(buf), write(handle,buf,len) != len ? do_something() : 0 ;

But hopefully you'd rather not.
			- Jeff.



More information about the Comp.lang.c mailing list