Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!usc!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 Message-ID: <14590@dartvax.Dartmouth.EDU> Date: 21 Jul 89 21:37:43 GMT References: <10099@mpx2.mpx.com> <93@microsoft.UUCP> <10100@mpx2.mpx.com> <10103@mpx2.mpx.com> <8468@batcomputer.tn.cornell.edu> <14582@dartvax.Dartmouth.EDU> <2990@nmtsun.nmt.edu> Sender: news@dartvax.Dartmouth.EDU Reply-To: ari@eleazar.dartmouth.edu (Ari Halberstadt) Organization: Dartmouth College, Hanover, NH Lines: 36 In article <2990@nmtsun.nmt.edu> dwho@nmtsun.nmt.edu (David Olix) writes: #>[Skipping all the "In article..." stuff] #>>[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! [...] #> #>Actually, "Mastering C" by Craig Bolon, SYBEX Inc., p. 273 says that #>parenthesis operators have the HIGHEST priority, therefore what's inside #>(myptr = my_func()) would get evaluated first. Also, it specifies that #>grouping for the '!=' operator is from left to right. Now, the author of #>this book may have been wrong.... Anyone seen an "official" statement #>from K&R? True, parenthesis have the highest priority, but that is not relavent. Syntactically, what you have is: while (expr1 != expr2) { ... } Since the two expressions are totally separate, the compiler is free to do whatever it chooses. The expressions become a single expression when (and only when) the compiler evaluates the != operator. The whole reason for not defining order of evaluation was to allow machines to evaluate things in the fastest way. Grouping is not the same as order of evaluation...it's been a while since I've gone over that, and I don't have a book in front of me right now. The ANSI C standard has formalized all these things, but again, I don't have a copy in front of me. -- 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