Path: utzoo!attcan!utgpu!watmath!iuvax!rutgers!uwvax!astroatc!glen From: glen@astroatc.UUCP (Glen Ecklund) Newsgroups: comp.lang.c Subject: Re: use of if (!cptr) and if (cptr) && a programming error Message-ID: <2486@astroatc.UUCP> Date: 2 Aug 89 14:15:52 GMT References: <10099@mpx2.mpx.com> <93@microsoft.UUCP> <10100@mpx2.mpx.com> <2990@nmtsun.nmt.edu> <18677@mimsy.UUCP> <10592@riks.csl.sony.JUNET> Reply-To: glen@astroatc.UUCP (Glen Ecklund) Organization: Astronautics Technology Cntr, Madison, WI Lines: 25 In article <10592@riks.csl.sony.JUNET> diamond@riks. (Norman Diamond) writes: ->Someone suggested: ->>>> while ( ( myptr = my_func() )->x != myptr->y ) -> ->In article <18677@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes: ->>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. -> ->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? Nope. Note that in the first example, the problem is not that the left use of myptr might get the wrong value, it is guaranteed to get the value returned by my_func(). The problem is that the right use of myptr could get either. The value of the expression (ch = getchar()) will similarly always be the value returned by getchar(). No problem. Glen