Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!dptg!att!cbnewsc!mackey From: mackey@cbnewsc.ATT.COM (ron.mackey) Newsgroups: comp.lang.c Subject: Remember precedence rules: (was Re: use of if (!cptr)) Message-ID: <1984@cbnewsc.ATT.COM> Date: 24 Jul 89 23:37:37 GMT References: <10099@mpx2.mpx.com> <93@microsoft.UUCP> <9042@chinet.chi.il.us> Organization: AT&T Bell Laboratories Lines: 38 In article <9042@chinet.chi.il.us>, les@chinet.chi.il.us(Leslie Mikesell)writes: > In article <10103@mpx2.mpx.com> erik@mpx2.mpx.com (Erik Murrey) writes: > > >while (myptr= my_func(), myptr->x != myptr->y) { > > ... > I'd use: > while (myptr = my_func() && myptr->x != myptr->y) { > > which would detect a null pointer returned by my_func() as well as > providing a guaranteed order of evaluation. It would also be incorrect since "&&" binds tighter than "=" Your expression would be evaluated as follows: while (myptr = (my_func() && (myptr->x != myptr->y))) { The order of evaluation is as follows: ----------------------------------------------- evaluate my_func() if (my_func() returns 0) then assign 0 to myptr else evaluate (myptr->x != myptr->y) if (myptr->x != myptr->y) then assign 1 to myptr else assign 0 to myptr ----------------------------------------------- Not exactly what the original poster requested, eh? Ron Mackey ihlpb!mackey AT&T Bell Laboratories (312) 979-2140