trigraphs in X3J11

Karl Heuer karl at haddock.ISC.COM
Wed May 25 08:28:14 AEST 1988


In article <10949 at apple.Apple.Com> lenoil at apple.UUCP (Robert Lenoil) writes:
>Instead of introducing [trigraphs], why not simply extend the backslash
>escape mechanism to be valid outside of strings?

That's an easy one: backslash is one of the characters that may not exist!

>This would allow the use of #defines
>#define ??< \173	/* open brace */
>#define ??> \175	/* close brace */

Not unless you extend the preprocessor's notion of what constitutes a valid
macro name.  Note also that the magic constants \173 and \175 are unportable.

In article <10941 at steinmetz.ge.com> davidsen at steinmetz.ge.com (William E. Davidsen Jr) writes:
>I scanned my local source directory and found three programs of 102 which
>would break. ... I did NOT scan the directory of programs which do device
>control, since I have made that point and every one would break and have to
>be handcoded with escape sequences, etc, do get by this.

Are you sure you have that many programs that would break?  Note that `??'
alone is not a problem; it becomes a trigraph only when followed by one of the
nine characters "=(/)'<!>-".  (Unlike backslash, which is reserved even if the
following character is unrecognized.)

Assuming trigraphs stay in, the fix is simple: filter your code through
	sed -e "s;??\\([-=(/)'<!>]\\);?\\\\?\\1;g"
as part of the ANSIfication process.  (Better yet, do it now before you run
into a compiler with trigraphs.  It won't hurt, unless your current compiler
complains about the unrecognized escape "\?".)

Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint



More information about the Comp.lang.c mailing list