Trigraphs and Pragmas

Joe Beckenbach beckenba at cit-vax.Caltech.Edu
Tue May 31 07:56:15 AEST 1988


[another novice's ventures into the waters...]

	I've seen various unhappiness on the net with trigraphs for
those who don't want to have to worry about them. I've even seen a 
suggestion for 
	#trigraph		[no disrespect, but UGH!]
and for
	#define ??<	\173	[strike 1: ??< not always substitutable,
				 strike 2: \ itself needs trigraph ]

Why not something like a `standard' pragma:
	#pragma trigraph warn
	about possible conversions when the programmer intended that
no trigraphs were written? Note that this pragma can be ignored on C
compilers which NEED trigraphs to express the language [ignored but warned
about, naturally].

To add to trigraph sequences, perhaps something like:
	#pragma trigraph LBRACE &<
to allow &< to map to {		[notice &< is never legal C!]
	#pragma trigraph o240 o140
to mess up some character mappings by replacing all occurances of the
source file character \140 [ASCII high space, national whatever] to the
8-bit character \240 [high ASCII space, national whatever #2].

	With appropriate work, the preprocessor could have equivalent
semantics for several different sequences mapping to characters. I
intentionally am limiting myself to mappings from  (n chars -> 1 char)
to avoid co-opting #define; if the extension (n chars -> m chars) is allowed,
the #define is a special case.
	For example, I might want to use the sequence @@@ to delimit
certain subsections of my files, eg where I need to do more work. Then a
simple remapping within the preprocessor handles this:
#pragma trigraph SPACE		@

	Another example, the ANSI trigraphs under this syntax would become:
#pragma trigraph HASH		??=
#pragma trigraph BSLASH		??/
#pragma trigraph CARET		??'
#pragma trigraph LBRACKET	??[
#pragma trigraph RBRACKET	??]
#pragma trigraph VBAR		??!
#pragma trigraph LBRACE		??<
#pragma trigraph RBRACE		??>
#pragma trigraph TILDE		??-
	or
#pragma trigraph HASH		o077o077o075
	if ASCII and the relevant ISO character set have the same octal codings.

If ASCII and the relevant ISO character standard differ in the 7-bit range, then
oxxx will stand for the ASCII 7-bit coding and something like ixxx will stand
for the ISO character equivalent.


	On related notes:
1- Where can I order the ANSI C standard?
2- Where can I find the registry of international (esp. character) standards,
	and also where can I get ordering information for such a body's work?
3- Who are the best people to circulate this sort of "standard #pragma" ideas,
	and will there be a standardized #pragma library available?
	[Or is that completely counter to the intention of the standards
	committee? Any committeemen (or Ritchie, or whoever) willing to comment?)
4- And how long until the first completely ANSI, non-pre-ANSI C will be out?
	[When this happens, then we all will know the transition is at hand.
	Of course, the wise compiler supporter will offer automatic filters
	to speed conversion between old and new.]

-- 
Joe Beckenbach	beckenba at csvax.caltech.edu	Caltech 1-58, Pasadena CA 91125
	BS E&AS (CS) 1988



More information about the Comp.lang.c mailing list