home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / c / 11523 < prev    next >
Encoding:
Internet Message Format  |  1992-07-23  |  1.3 KB

  1. Path: sparky!uunet!mcsun!sun4nl!and!jos
  2. From: jos@and.nl (Jos Horsmeier)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Concatenation of two macros?
  5. Message-ID: <3159@dozo.and.nl>
  6. Date: 23 Jul 92 15:58:11 GMT
  7. References: <1FE7B81211DF800725@ursula.lucas.lu.se>
  8. Organization: AND Software BV Rotterdam
  9. Lines: 32
  10.  
  11. In article <1FE7B81211DF800725@ursula.lucas.lu.se> KOSU_MATSB@ROUTH.KOSUFY.LU.SE writes:
  12. |
  13. |    Concatenation of two macros. Is it possible?
  14. |
  15. |    If i have the following two definitions:
  16. |        #define A pre
  17. |        #define B post
  18. |    And want to "#define C" to be  "prepost" BUT as an 
  19. |    expression of A and B! How do i do it?
  20. |    #define C (expression of A and B to yield prepost)
  21.  
  22. Most pre-ANSI C preprocessors allow you to do the following trick:
  23.  
  24. #define C(A, B) A/**/B
  25.  
  26. A conformant ANSI-C preprocessor inserts at least one white space
  27. character when replacing the empty comment in the replacement list,
  28. but they came up with the following (what I call `ugly') construct:
  29.  
  30. #define C(A, B) A ## B
  31.  
  32. The `##' operator `glues' the two operands together and the resulting
  33. preprocessing token is available for replacement in the rescan phase
  34. of the macro expansion.
  35.  
  36. kind regards,
  37.  
  38. Jos aka jos@and.nl
  39.  
  40. ps. I just call this thingy `ugly', because it doesnt' `look good'
  41.     to me. The same counts for the trigraph characters. Yuck!
  42.     Maybe I'm just too old ... dunno ... ;-)
  43.