Xref: utzoo comp.lang.c:12547 comp.lang.fortran:1087 Path: utzoo!attcan!uunet!sdrc!scjones From: scjones@sdrc.UUCP (Larry Jones) Newsgroups: comp.lang.c,comp.lang.fortran Subject: Re: C associativity rules Keywords: associativity, expressions Message-ID: <382@sdrc.UUCP> Date: 13 Sep 88 22:42:04 GMT References: <412@marob.MASA.COM> Organization: Structural Dynamics Research Corp., Cincinnati Lines: 22 In article <412@marob.MASA.COM>, samperi@marob.MASA.COM (Dominick Samperi) writes: > Does K&R C or the new ANSI C permit the compiler to evaluate an expression > like a+b+c in any order it pleases, rather than in the strict left-to-right > order (a+b)+c ? I've always assumed that a strict left-to-right order would > be used, as is the case for relational expressions like the one in the > following. > while(i != -1 && a[i] != k) > whatever ; K&R has always allowed the compiler to evaluate in any order at all (even in the presence of parentheses). The only operators which are guaranteed to evaluate left-to-right are "&&", "||", and ",". Ansi now requires compilers to evaluate "as if" they honored parentheses, and perhaps even associativity in unparenthesized expressions (there's still some debate as to exactly what the wording says). ---- Larry Jones UUCP: uunet!sdrc!scjones SDRC scjones@sdrc.uucp 2000 Eastman Dr. BIX: ltl Milford, OH 45150 AT&T: (513) 576-2070 "Save the Quayles" - Mark Russell