home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / std / c / 3399 < prev    next >
Encoding:
Text File  |  1993-01-22  |  1.8 KB  |  46 lines

  1. Newsgroups: comp.std.c
  2. Path: sparky!uunet!spool.mu.edu!agate!doc.ic.ac.uk!rhbnc!cscx!andreww
  3. From: andreww@cscx.cs.rhbnc.ac.uk (Andrew Waters)
  4. Subject: Re: Macro replacement
  5. Message-ID: <1993Jan22.121437.10384@csqx.cs.rhbnc.ac.uk>
  6. Sender: andreww@cscx (Andrew Waters)
  7. Nntp-Posting-Host: cscx.rhbnc.ac.uk
  8. Reply-To: andreww@dcs.rhbnc.ac.uk (Andrew Waters)
  9. Organization: Dept of Comp Sci, Royal Holloway & Bedford New College Uni London
  10. References: <SJA.93Jan16184647@lk-hp-2.hut.fi> <1ja816INNhlh@chnews.intel.com> <526@heimdall.sdrc.com>
  11. Date: Fri, 22 Jan 1993 12:14:37 GMT
  12. Lines: 32
  13.  
  14. The example given in the standard (section 3.8.3.5) makes use of an ambiguity
  15. pointed out in the rational.
  16.  
  17. e.g. (taking only the relavent part)
  18.  
  19. #define x    2
  20. #define f(a)    f(x * (a))
  21. #define g    f
  22. #define    t(a)    a
  23.  
  24. t(t(g)(0))
  25.  
  26. which the standard has going to f(2 * (0)) however if we follow the expansion:
  27.  
  28. 1.  Examine the string and find the outermost macro name "t"
  29. 2.  Search for the argument "t(g)(0)"
  30. 3.  Expand the arguments - finding the inner macro name "t"
  31. 4.  Search for the argument "g"
  32. 5.  Expand the arguments - finding the macro name "g" which expands to "f"
  33. 6.  Rescan the replacement list of "g"  i.e. rescan "f".  There is a macro f
  34.     but it requires an open parenthesis which we do not have therefore we cannot
  35.     expand any further.
  36. 7.  Rescan the replacement list of innermost "t" i.e. rescan "f".  This has
  37.     already been expanded fully.
  38. 8.  Rescan the replacement list of outermost "t" i.e. rescan "f(0)".  Now what
  39.     happens.  Clearly there is a macro call however "f" is a macro name which
  40.     has not been replaced and therefore is not available for further replacement.
  41.  
  42. So we have two answers
  43.  
  44. "f(2 * (0))" in the standard,  but just as legally "f(0)".  Surely a poor
  45. example to illustrate expansion rules.
  46.