Path: utzoo!attcan!utgpu!watmath!att!dptg!rutgers!cs.utexas.edu!uunet!mcvax!ukc!axion!tigger!raph From: raph@tigger.planet.bt.co.uk (Raphael Mankin) Newsgroups: comp.lang.c Subject: Re: use of if (!cptr) and if (cptr), where cptr is a * Summary: Operator precedence in C Keywords: * != int Message-ID: <526@tigger.planet.bt.co.uk> Date: 28 Jul 89 08:08:38 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> <14590@dartvax.Dartmouth.EDU> Organization: RT5111, BTRL, Martlesham Heath, England Lines: 37 ari@eleazar.dartmouth.edu (Ari Halberstadt) writes: >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.] >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. The order of evaluation of operands and the order of application of operators have little to do with each other. The compiler could evaluate _all_ the operands before applying _any_ operators (except && ||). This applies also to the order of evaluation of subscripts and function arguments. If there are side effects you are in dangerous waters - so don't do it. A typical, and particularly blatant, case is a[i] = b[i++]; or a[i++] = b[i]; Some compilers will diagnose this. although the compiler has to compute the RHS before it uses the LHS, there is nothing to stop it evaluating the LHS so as to obtain the destination address before evaluating the RHS.