() ignored in some expressions

News system news at ism780c.isc.com
Fri Apr 13 10:48:58 AEST 1990


In article <1272 at sdrc.UUCP> scjones at sdrc.UUCP (Larry Jones) writes:
>In article <48079 at lanl.gov>, u096000 at lanl.gov (Roger A. Cole) writes:
>> In K&R1, expressions involving one of the associative and commutative
>> operators can be arranged even when parenthesized.
>
>Well, if the operators ARE commutative and associative, it
>doesn't make any difference!  In the environment the C grew up
>in, integer arithmetic overflows wrap around without producing
>any exceptions, so the integer operators really are associative
>and commutative.

A common misconception.  Integer operators are associaive for add and
subtract but not for multiply and divide.  for example:

    long x=70000;
    x*(x/x);   /* 700000 if parens are honored */
    (x*x)/x;   /* 8643   if parens are honered */

The above assumes longs are 32 bits.

    Marv Rubinstein



More information about the Comp.lang.c mailing list