home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / c / 18809 < prev    next >
Encoding:
Internet Message Format  |  1992-12-22  |  1.9 KB

  1. Path: sparky!uunet!munnari.oz.au!goanna!ok
  2. From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Questions about token merging and trigraphs
  5. Message-ID: <16297@goanna.cs.rmit.oz.au>
  6. Date: 23 Dec 92 03:56:50 GMT
  7. References: <mcdonald.625@aries.scs.uiuc.edu> <yoF4VB1w165w@quest.UUCP>
  8. Organization: Comp Sci, RMIT, Melbourne, Australia
  9. Lines: 31
  10.  
  11. In article <yoF4VB1w165w@quest.UUCP>, kdq@quest.UUCP (Kevin D. Quitt) writes:
  12. >     Would you like to post some of the CODE that got broken?
  13. > Considering that ?? is *not* legal anywhere in C (except in comments,
  14. > strings and header names) I doubt you can do it.
  15.  
  16. Here is a program which was legal in K&R C and may misbehave rather
  17. seriously in ANSI C.  (As it happens, I _have_ on occasion used "?"s
  18. as place-holders to be overwritten.  These days I use "X"s.)  ??/ was
  19. also likely to appear in filename templates.
  20.  
  21. char filename[] = "D??-??-??";
  22.  
  23. void fill02d(p, n) char *p; int n;
  24. { p[0] = (n/10)%10 + '0'; p[1] = n%10 + '0'; }
  25.     
  26. void mkfilename(y, m, d) int y, m, d;
  27. { fill02d(filename+1, y); fill02d(filename+4, m); fill02d(filename+7, d); }
  28.  
  29. In K&R C, the call mkfilename(1992, 12, 23) resulted in filename
  30. containing "D92-12-23".  In ANSI C, strlen(filename) starts out at 5,
  31. so the last call to fill02d isn't going to work very well.
  32.  
  33. It is so easy to check for unintended digraphs and so easy to fix them
  34. that I don't actually worry about this.  I do find it amusing, though,
  35. that the easy fix (changing ?? to ?\?) involves one of the very characters
  36. that has a trigraph (??/ => \).  Suppose we decide to use the trigraph for
  37. backslash, and instead of writing ?\? write ???/?.  Unfortunately, that
  38. won't be parsed correctly, because ??? is not one of the recognised
  39. trigraphs, it will be left untouched.  You _must_ use ?\? or string
  40. pasting to break up the question marks.  And if you _can_ use ?\?, you
  41. didn't need trigraphs.
  42.