Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!ames!apple!bloom-beacon!bu-cs!dartvax!eleazar.dartmouth.edu!ari From: ari@eleazar.dartmouth.edu (Ari Halberstadt) Newsgroups: comp.lang.c Subject: Re: use of if (!cptr) and if (cptr) && a programming error Summary: A VERY serious programming error Message-ID: <14582@dartvax.Dartmouth.EDU> Date: 21 Jul 89 16:39:05 GMT References: <10099@mpx2.mpx.com> <93@microsoft.UUCP> <10100@mpx2.mpx.com> <10103@mpx2.mpx.com> <8468@batcomputer.tn.cornell.edu> Sender: news@dartvax.Dartmouth.EDU Reply-To: ari@eleazar.dartmouth.edu (Ari Halberstadt) Organization: Dartmouth College, Hanover, NH Lines: 20 In article <8468@batcomputer.tn.cornell.edu> lacey@tcgould.tn.cornell.edu (John Lacey) writes: >In article <10103@mpx2.mpx.com> erik@mpx2.mpx.com (Erik Murrey) writes: >[Material everybody has seen n times deleted.] >I am kind of butting in [ :-) ], but how 'bout > while ( ( myptr = my_func() )->x != myptr->y ) > { > } THAT WILL NOT WORK! I quote here from the book "C Traps and Pit Falls" by Andrew Koenig (Addison-Wesley, 1989), pp. 47: Only the four C operators &&, ||, ?:, and , specify an order of evaluation. What this means for the above code is that the machine is free to evaluate "myptr->y" before "myptr" is assigned a value by my_func(). While it may work with a certain compiler on a certain machine, you may wake up tomorrow and discover some very wierd bugs! -- Ari Halberstadt '91, "Long live succinct signatures" E-mail: ari@eleazar.dartmouth.edu Telephone: (603)640-5687 Mailing address: HB1128, Dartmouth College, Hanover NH 03755