() ignored in some expressions

Benjamin Zhu zhu at crabcake.cs.jhu.edu
Fri Apr 13 15:01:11 AEST 1990


In article <41297 at ism780c.isc.com> marv at ism780.UUCP (Marvin Rubenstein) writes:
>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:
 ^^^^^^^^

Oh, really? How about 1-2+3-4, 1-(2+3)-4, ...
Well, you can enumerate all of the combinations. Are the results all 0?
I am confused.

Strictly speaking, the integer operations are associative only if a single
operator is involved.  Otherwise, you could never tell.

Sigh, algebra is still useful.

>
>    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


Benjamin Zhu
=========================================================================
Sorry, but I have no disclaimer for you this time.
=========================================================================



More information about the Comp.lang.c mailing list