home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / c / 16319 < prev    next >
Encoding:
Text File  |  1992-11-11  |  2.6 KB  |  65 lines

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