Trigraphs (was: Portable Self-Replicating C Contest)

Karl Heuer karl at haddock.ima.isc.com
Wed Apr 19 10:47:30 AEST 1989


In article <10159 at socslgw.csl.sony.JUNET> diamond@ (Norman Diamond) writes:
>In article <12629 at haddock.ima.isc.com> karl at haddock (Karl Heuer) writes:
>>`printf("??=")' will output `#', not `??='.
>
>Yes indeed, such conversions take place even in strings.  I wonder how
>such programs execute in environments that don't have a '#' character.

The C constant expression ('#'), or its alternate spelling ('??='), even
though it might not correspond to any printable glyph, must have a value
distinct from any other character.  Since the implementation is allowed to
apply a fairly arbitrary mapping when writing to a text stream, it's entirely
possible for this to be written to the device as a digraph `$=', for example,
where `$' is any convenient unused value.  (It needn't even be printable,
though this would be convenient for a terminal device.)

Given such a mapping, and its inverse on input streams, it will appear to any
conforming C program *as if* the execution environment really did have a `#'
character.  In particular, an editor or compiler written in C would
automatically do the right thing.  This is why I consider trigraphs to be
unnecessary: a transparent mapping is already guaranteed to exist.  Alas, the
feature was too deeply entrenched in the Draft by the time I realized this.

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



More information about the Comp.std.c mailing list