home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / std / c / 3420 < prev    next >
Encoding:
Internet Message Format  |  1993-01-25  |  3.3 KB

  1. Path: sparky!uunet!psinntp!heimdall!thor!scjones
  2. From: scjones@thor.sdrc.com (Larry Jones)
  3. Newsgroups: comp.std.c
  4. Subject: Re: Macro replacement
  5. Message-ID: <560@heimdall.sdrc.com>
  6. Date: 25 Jan 93 23:48:43 GMT
  7. References: <SJA.93Jan16184647@lk-hp-2.hut.fi> <1ja816INNhlh@chnews.intel.com> <1993Jan22.121437.10384@csqx.cs.rhbnc.ac.uk>
  8. Sender: news@heimdall.sdrc.com
  9. Lines: 68
  10.  
  11. In article <1993Jan22.121437.10384@csqx.cs.rhbnc.ac.uk>, andreww@cscx.cs.rhbnc.ac.uk (Andrew Waters) writes:
  12. > The example given in the standard (section 3.8.3.5) makes use of an ambiguity
  13. > pointed out in the rational.
  14.  
  15. No, it doesn't.
  16.  
  17. > #define x    2
  18. > #define f(a)    f(x * (a))
  19. > #define g    f
  20. > #define    t(a)    a
  21. > t(t(g)(0))
  22. > 1.  Examine the string and find the outermost macro name "t"
  23. > 2.  Search for the argument "t(g)(0)"
  24. > 3.  Expand the arguments - finding the inner macro name "t"
  25. > 4.  Search for the argument "g"
  26. > 5.  Expand the arguments - finding the macro name "g" which expands to "f"
  27. > 6.  Rescan the replacement list of "g"  i.e. rescan "f".  There is a macro f
  28. >     but it requires an open parenthesis which we do not have therefore we cannot
  29. >     expand any further.
  30.  
  31. Correct so far, but note that f is *not* a nested instance of a macro
  32. being replaced, so it is *not* marked as unavailable for further expansion.
  33.  
  34. > 7.  Rescan the replacement list of innermost "t" i.e. rescan "f".  This has
  35. >     already been expanded fully.
  36. > 8.  Rescan the replacement list of outermost "t" i.e. rescan "f(0)".  Now what
  37. >     happens.  Clearly there is a macro call however "f" is a macro name which
  38. >     has not been replaced and therefore is not available for further replacement.
  39.  
  40. But, as I noted above, it has not been marked unavailable, so it *is*
  41. expanded, leading to the "f(2 * (0))" result shown in the example in
  42. the standard.  The example given in the Rationale is quite different:
  43.  
  44. #define f(a)  a * g
  45. #define g(a)  f(a)
  46.  
  47. f(2)(9)
  48.  
  49. 1.  Examine the string and find the macro name "f" followed by "("
  50. 2.  Identify the argument "2"
  51. 3.  Expand the arguments - nothing to do
  52. 4.  Substitute arguments into replacement list "2 * g"
  53. 5.  Rescan the replacement list with the rest of the source file
  54. 6.  Find the macro name "g" followed by "("
  55. 7.  Identify the argument "9"
  56. 8.  Expand the arguments - again, nothing to do
  57. 9.  Substitute arguments into replacement list "f(9)"
  58. 10. Rescan the replacement list with the rest of the source file
  59. 11. Find the macro name "f" followed by "("
  60.  
  61. This is the ambiguity: is "f" at this point a nested replacement?
  62.  
  63. Since this "f" came from the expansion of "g" which in turn came from
  64. the expansion of "f", you can certainly argue that it is and thus it
  65. should not be replaced and it should be marked unavailable for further
  66. replacement.  On the other hand, you can argue that as soon as you went
  67. past the end of "g"'s expansion into the rest of the source file you are
  68. no longer expanding "g" or "f" and thus this "f" is *not* a nested
  69. replacement and should be replaced normally.  The Standard does not take
  70. sides in this argument; either result is acceptable.
  71. ----
  72. Larry Jones, SDRC, 2000 Eastman Dr., Milford, OH  45150-2789  513-576-2070
  73. larry.jones@sdrc.com
  74. I always send Grandma a thank-you note right away.  ...Ever since she
  75. sent me that empty box with the sarcastic note saying she was just
  76. checking to see if the Postal Service was still working. -- Calvin
  77.