mackey@cbnewsc.ATT.COM (ron.mackey) (07/25/89)
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
les@chinet.chi.il.us (Leslie Mikesell) (07/26/89)
In article <1984@cbnewsc.ATT.COM> mackey@cbnewsc.ATT.COM (ron.mackey) writes: >> while (myptr = my_func() && myptr->x != myptr->y) { >It would also be incorrect since "&&" binds tighter than "=" >Your expression would be evaluated as follows: Oops - point well taken; make that: while ((myptr = my_func()) && myptr->x != myptr->y) { ...and I just checked some code to make sure I had actually done it that way. Les Mikesell