C associativity rules
Larry Jones
scjones at sdrc.UUCP
Wed Sep 14 08:42:04 AEST 1988
In article <412 at marob.MASA.COM>, samperi at 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 at sdrc.uucp
2000 Eastman Dr. BIX: ltl
Milford, OH 45150 AT&T: (513) 576-2070
"Save the Quayles" - Mark Russell
More information about the Comp.lang.c
mailing list