Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!pt.cs.cmu.edu!andrew.cmu.edu!jdr+ From: jdr+@andrew.cmu.edu (Jeff Rosenfeld) Newsgroups: comp.lang.c Subject: Re: evaluation order Message-ID: Date: 14 Sep 89 12:28:51 GMT References: <9361@attctc.Dallas.TX.US> Distribution: na Organization: Carnegie Mellon, Pittsburgh, PA Lines: 25 In-Reply-To: <9361@attctc.Dallas.TX.US> > Excerpts from netnews.comp.lang.c: 14-Sep-89 evaluation order Bob > Calbridge@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.