home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!usc!sdd.hp.com!zaphod.mps.ohio-state.edu!uunet.ca!wildcan!sq!msb
- From: msb@sq.sq.com (Mark Brader)
- Subject: Re: retrospective on evaluation order
- Message-ID: <1992Nov11.064622.22339@sq.sq.com>
- Organization: SoftQuad Inc., Toronto, Canada
- References: <1dau8nINNk59@uranium.sto.pdb.sni.de> <qBak-G@ppcger.ppc.sub.org> <1992Nov9.173126.11069@athena.mit.edu>
- Date: Wed, 11 Nov 92 06:46:22 GMT
- Lines: 54
-
- At the end of a very nice article, Steve Summit (scs@adam.mit.edu) writes:
-
- > P.S. In this article, I have deliberately been casual rather
- > than rigorous in my explanations. (In particular, I have freely
- > used the term "precedence" which Chris correctly points out can
- > be superfluous as well as misleading.)
-
- I would like to point out one more place where Steve was casual.
- He wrote:
-
- > In the expression
- >
- > d + e + f
- >
- > ... associativity tells us that d should be added to e and the
- > sum added to f, i.e. that it should be evaluated as
- >
- > (d + e) + f
-
- And later:
-
- > We can now turn to a couple of final points, the first of
- > historical interest only. K&R ("Classic") C gave a compiler
- > license to rearrange associative operators. That is, given
- >
- > d + e + f
- >
- > , the compiler might emit code to add e to f first, or even d to f.
- > This license has been revoked under ANSI C ...
-
- The possibly confusing term here is "associativity". The reason it's
- confusing is that it might be taken to imply that + is an associative
- operator... i.e., that (d+e)+f HAS TO be equal to d+(e+f). In fact
- that isn't what the term means. It refers to the property of the
- formal definition which implies that, as the paragraph says, d+e+f
- is treated like (d+e)+f. The casual term "associativity" for this
- arises because this property is sometimes described with words such
- as "the + operator associates left to right". To above this confusion,
- some of us prefer to use the verb "groups" here instead.
-
- The reason this is significant is precisely that the operations +
- and * are _not_ necessarily associative on a computer. In ordinary
- arithmetic, of course, they _are_ associative, and THAT is what the
- reference to "associative" in K&R and in the last quoted text means.
-
- For comparison, note that the - operator is not associative in ordinary
- arithmetic, nor on a computer of course; but it too "associates [or
- groups] left to right", because c-p-r means (c-p)-r.
- --
- Mark Brader "What a strange field. Studying beings instead
- SoftQuad Inc., Toronto of mathematics. Could lead to recursive
- utzoo!sq!msb, msb@sq.com problems in logic." -- Robert L. Forward
- (The Flight of the Dragonfly)
- This article is in the public domain.
-