Path: utzoo!attcan!uunet!samsung!uakari.primate.wisc.edu!ames!haven!umd5!crabcake!zhu From: zhu@crabcake.cs.jhu.edu (Benjamin Zhu) Newsgroups: comp.lang.c Subject: Re: () ignored in some expressions Message-ID: <1380@crabcake> Date: 13 Apr 90 05:35:11 GMT References: <48079@lanl.gov> <1272@sdrc.UUCP> <41297@ism780c.isc.com> Reply-To: zhu@crabcake.cs.jhu.edu (Benjamin Zhu) Followup-To: comp.lang.c Organization: Johns Hopkins University CS Dept -- Town of Solitude Lines: 40 Keywords: In article <41297@ism780c.isc.com> marv@ism780.UUCP (Marvin Rubenstein) writes: >In article <1272@sdrc.UUCP> scjones@sdrc.UUCP (Larry Jones) writes: >>In article <48079@lanl.gov>, u096000@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. =========================================================================