Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ncar!tank!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: use of if (!cptr) and if (cptr) && a programming error Message-ID: <18677@mimsy.UUCP> Date: 21 Jul 89 20:50:46 GMT References: <10099@mpx2.mpx.com> <93@microsoft.UUCP> <10100@mpx2.mpx.com> <2990@nmtsun.nmt.edu> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 49 In article <2990@nmtsun.nmt.edu> dwho@nmtsun.nmt.edu (David Olix) writes: >> while ( ( myptr = my_func() )->x != myptr->y ) >>THAT WILL NOT WORK! [...] Or, more precisely, is not guaranteed. >Actually, "Mastering C" by Craig Bolon, SYBEX Inc., p. 273 says that >parenthesis operators have the HIGHEST priority, If by `priority' you mean (or Bolon means) `precedence', this is true, but: >therefore what's inside (myptr = my_func()) would get evaluated first. this conclusion is unwarranted. >Also, it specifies that grouping for the '!=' operator is from left to >right. This is again correct. Grouping and precedence are matters of parsing; that is, in the absence of parentheses, a != b != c is parsed the same way as (a != b) != c Parentheses, having extreme prej, er, precendence, can alter the grouping. But grouping is not related to order of evaluation. This should be obvious if you consider that while (a == b) has no grouping at all, but certainly does have *some* order of evaluation. Some languages (e.g., FORTRAN) make various constraints on evaluation order based on specific grouping constructs (e.g., parentheses), but traditionally, C has not done so. The pANS makes some limited constraints, but not enough to warrant the conclusion quoted above. In short, whether `myptr->y' is obtained before or after `(fncall)->x' is not defined in C, and different implementations do in fact have different evaluation order. Koenig's _C_Traps_and_Pitfalls_ is again correct. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris