Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!cs.utexas.edu!uunet!kddlab!titcca!sragwa!wsgw!socslgw!diamond From: diamond@csl.sony.JUNET (Norman Diamond) Newsgroups: comp.lang.c Subject: Re: use of if (!cptr) and if (cptr) && a programming error Message-ID: <10592@riks.csl.sony.JUNET> Date: 24 Jul 89 02:08:09 GMT References: <10099@mpx2.mpx.com> <93@microsoft.UUCP> <10100@mpx2.mpx.com> <2990@nmtsun.nmt.edu> <18677@mimsy.UUCP> Reply-To: diamond@riks. (Norman Diamond) Organization: Sony Computer Science Laboratory Inc., Tokyo, Japan Lines: 40 Someone suggested: >>> while ( ( myptr = my_func() )->x != myptr->y ) In article <2990@nmtsun.nmt.edu> dwho@nmtsun.nmt.edu (David Olix) writes: >>THAT WILL NOT WORK! [...] Many people argued that it should work, because of the parentheses. (I almost did too, but continued reading first to see if anyone else did.) In article <18677@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes: >Or, more precisely, is not guaranteed. [...] >The pANS makes some limited constraints, but not enough to warrant the >conclusion [that it will work]. > >In short, whether `myptr->y' is obtained before or after `(fncall)->x' >is not defined in C, and different implementations do in fact have >different evaluation order. (Thanks to Chris Torek for closing my mouth before I put my foot in it.) But! What about the following famous idiom! int ch; /* everyone knows it cannot be char */ while ((ch = getchar()) != EOF) { ... } The old value of ch might be compared to EOF? The loop might be executed in incorrect cases (and might not be executed sometimes when it should be)? IS THIS REALLY TRUE ?????????????????? Are there really millions of broken C programs due to this idiom? -- -- Norman Diamond, Sony Computer Science Lab (diamond%csl.sony.jp@relay.cs.net) The above opinions are inherited by your machine's init process (pid 1), after being disowned and orphaned. However, if you see this at Waterloo or Anterior, then their administrators must have approved of these opinions.