C associativity rules

Doug Gwyn gwyn at smoke.ARPA
Tue Sep 13 23:45:48 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)

Why burden the net with this when it is easy to find in K&R?
The theoretically associative and commutative operators have
always been allowed to be rearranged in C.  Before ANSI C (which
hasn't happened yet!), this was true even if the programmer
tried to enforce a particular grouping with parentheses (unlike
Fortran).

The operands of || and && operators obviously cannot be evaluated
in reverse order due to the very definition of the || and &&
operators.



More information about the Comp.lang.c mailing list