home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / std / c / 3389 < prev    next >
Encoding:
Internet Message Format  |  1993-01-21  |  1.8 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: <526@heimdall.sdrc.com>
  6. Date: 21 Jan 93 15:42:47 GMT
  7. References: <SJA.93Jan16184647@lk-hp-2.hut.fi> <1ja816INNhlh@chnews.intel.com>
  8. Sender: news@heimdall.sdrc.com
  9. Lines: 37
  10.  
  11. In article <1993Jan19.180718.3482@csqx.cs.rhbnc.ac.uk> [which hasn't
  12. arrived here yet], andreww@cscx.cs.rhbnc.ac.uk (Andrew Waters) writes:
  13. > Is this truely more logical?  Look at the example:
  14. > #define echo(a) { a ; x }
  15. > #define x       2 * x
  16. > echo (x)
  17. > As before the macro argument "x" is replaced giving the replacement list
  18. > { 2 * x ; x }
  19. > We now examine this replacement list for further macro expansion.  "x" is no
  20. > longer available for replacement,  giving the final result
  21. > { 2 * x ; x }
  22.  
  23. No.  The rule in the standard about nonreplacable macro names says:
  24.  
  25.     These nonreplaced macro name preprocessing tokens are no longer
  26.     available for further replacement...
  27.  
  28. Note carefully that it's talking about the individual preprocessing
  29. tokens, not the macro in general.  Thus, when "x" is expanded to "2 * x"
  30. in the above example, the "x" in the replacement string is not replaced
  31. and *that particular token* is marked unavailable for further
  32. replacement, not the macro x.  Thus, when "{ 2 * x ; x }" is rescanned,
  33. the first "x" would be replacable, but it has been marked and so is left
  34. alone.  The second "x" has not been marked, so it is replaced normally
  35. giving "{ 2 * x ; 2 * x }".  Now the second "x" has also been marked so
  36. that if this string is later rescanned neither "x" will be replaced
  37. again.
  38. ----
  39. Larry Jones, SDRC, 2000 Eastman Dr., Milford, OH  45150-2789  513-576-2070
  40. larry.jones@sdrc.com
  41. It doesn't have a moral, does it?  I hate being told how to live my life.
  42. -- Calvin
  43.