Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!purdue!decwrl!pyramid!cbmvax!vu-vlsi!mpx1!mpx2!erik From: erik@mpx2.mpx.com (Erik Murrey) Newsgroups: comp.lang.c Subject: Re: use of if (!cptr) and if (cptr), where cptr is a * Message-ID: <10103@mpx2.mpx.com> Date: 20 Jul 89 19:12:45 GMT References: <10099@mpx2.mpx.com> <93@microsoft.UUCP> <10100@mpx2.mpx.com> Reply-To: erik@mpx2.mpx.com (Erik Murrey) Organization: MPX Data Systems, Inc. , Wayne, PA Lines: 53 In article wjc@ho5cad.ATT.COM (Bill Carpenter) writes: >In article <10100@mpx2.mpx.com> erik@mpx2.mpx.com (Erik Murrey) writes: >> struct xyzzy *sptr; >> if (sptr= my_function(), sptr->x == 0) >> printf("x is zero\n"); >> >> I think the second is much clearer. This looks even better as the >> pointers get more complex, since the pointer operators go right >> on the ptr itself, and not on an expression. > >Since there was no indication that this was intended as a joke ... > >I'll admit that this cloudy fragment looks clearer than the other >one you cited, but what the heck is wrong with (besides not checking >"sptr" being null): > > struct xyzzy *sptr; > sptr= my_function(); > if (sptr->x == 0) > printf("x is zero\n"); Maybe its hard for you to read, but I'm used to it. Perhaps my example was bad. The above coding method is even more useful in while() and for() loops: while (cc= fgetc(fp), cc != '\n') { /* process more of line */ ... } or even: while (myptr= my_func(), myptr->x != myptr->y) { /* ... */ ... } I would kinda like to see that one in your style... ... Erik -- Erik Murrey /| // /~~~~/ | / MPX Data Systems, Inc. / | / / /____/ |/ erik@mpx.com / / / / /| Data Systems, Inc. {vu-vlsi, bpa, cbmvax}!mpx1!erik / / / / |====================