home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / c / 18312 < prev    next >
Encoding:
Text File  |  1992-12-14  |  2.9 KB  |  76 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!ira.uka.de!math.fu-berlin.de!news.th-darmstadt.de!rbg.informatik.th-darmstadt.de!misar
  3. From: misar@rbg.informatik.th-darmstadt.de (walter misar)
  4. Subject: Re: Questions about token merging and trigraphs
  5. Sender: news@news.th-darmstadt.de (The News System)
  6. Message-ID: <1992Dec14.105753@rbg.informatik.th-darmstadt.de>
  7. Date: Mon, 14 Dec 1992 09:57:53 GMT
  8. References:  <42098@pprg.eece.unm.edu.pprg.unm.edu>
  9. Nntp-Posting-Host: rbhp60.rbg.informatik.th-darmstadt.de
  10. Organization: TU Darmstadt
  11. Lines: 63
  12.  
  13. In article <42098@pprg.eece.unm.edu.pprg.unm.edu>, ele@chama.eece.unm.edu writes:
  14. > Two questions about ANSI C:
  15. > (1) How is the preprocessor token merging mechanism (##) supposed to
  16. > be used?  I know, for example that if you have
  17. > #define X(i)  x ## i
  18. > then the preprocessor will replace code like 'X(1)' with 'x1', but
  19. > could someone give me an example of where this (or some other use of
  20. > '##') would be useful?
  21.  
  22. I used it once
  23. /* flags */
  24.  
  25. #define F_C     1<<0    /* Carry        */
  26. #define F_Z     1<<1    /* Zero         */
  27. #define F_I     1<<2    /* Interrupt    */
  28. #define F_D     1<<3    /* Decimal      */
  29. #define F_B     1<<4    /* Break        */
  30. #define F__     1<<5    /* - unused -   */
  31. #define F_V     1<<6    /* oVerflow     */
  32. #define F_N     1<<7    /* Negative     */
  33.  
  34. #define SET(flag)       (P|=(F_##flag))
  35. #define CLR(flag)       (P&=(~F_##flag))
  36. #define EQU(flag,val)   ((val)?SET(flag):CLR(flag))
  37. #define QUERY(flag)     (!!(P&F_##flag))
  38.  
  39. Now you can call SET(C) and it will set the C-flag (BTW this flags are 6502).
  40.  
  41.  
  42. > (2) There is a command-line switch to disable the 'trigraph' feature
  43. > in the gcc compiler.  What are trigraphs?  From the comments in the
  44. > gcc documentation I gather that they are something that the ANSI
  45. > committee has added to C and that Richard Stallman doesn't care for
  46. > them.  If that is the case, I'm wondering what purpose the ANSI
  47. > committee saw for them, why anyone would object to them, and, most
  48. > importantly, what they are.
  49.  
  50. Trigraphs are only of interest, if your machine hasn't got a full set of ASCII
  51. characters. All begin with ??, only following nine replacements take place:
  52. ??( [   ??< {   ??' ^
  53. ??) ]   ??> }   ??- ~
  54. ??= #   ??! |   ??/ \ 
  55. The replacement takes effect before any other preprocessor action, thus ??/
  56. may be used at the end of a line to merge it with the next. In general, I can't
  57. see a good reason for it - I can't believe one will actually programm s.th like
  58. this (Yeah it's ANSI)
  59.  
  60. ??=include <stdio.h>
  61. int main(int argc,char * argv??(??))
  62. ??<
  63. printf("Hello world !")
  64. return 0;
  65. ??>
  66.  
  67. Worse, trigraph can turn otherwise correct programs into garbage (especially
  68. ??! is a prime candidat)
  69. -- 
  70. Walter Misar                        It is impossible to enjoy idling thoroughly
  71. misar@rbg.informatik.th-darmstadt.de       unless one has plenty of work to do.
  72.