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