🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #5912

Trigraphs (was: Portable Self-Replicating C Contest)

#5912
From: Karl Heuer
Date: Wed, 19 Apr 1989 00:47
23 lines
1994 bytes
In article <10159@socslgw.csl.sony.JUNET> diamond@ (Norman Diamond) writes:
>In article <12629@haddock.ima.isc.com> karl@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@haddock.isc.com), The Walking Lint
Technical Details
Message-ID: <12743@haddock.ima.isc.com>
Path: arc1-ca.pugleaf.net!utzoo!dptcdc!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!bloom-beacon!bu-cs!purdue!decwrl!decvax!ima!haddock!karl
References: <12144@haddock.ima.isc.com> <12593@haddock.ima.isc.com> <6647@bsu-cs.bsu.edu> <12629@haddock.ima.isc.com> <10159@socslgw.csl.sony.JUNET>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!dptcdc!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!bloom-beacon!bu-cs!purdue!decwrl!decvax!ima!haddock!karl
From: karl@haddock.ima.isc.com (Karl Heuer)
Newsgroups: comp.std.c
Subject: Trigraphs (was: Portable Self-Replicating C Contest)
Message-ID: <12743@haddock.ima.isc.com>
Date: 19 Apr 89 00:47:30 GMT
References: <12144@haddock.ima.isc.com> <12593@haddock.ima.isc.com> <6647@bsu-cs.bsu.edu> <12629@haddock.ima.isc.com> <10159@socslgw.csl.sony.JUNET>
Reply-To: karl@haddock.ima.isc.com (Karl Heuer)
Organization: Interactive Systems, Boston
Lines: 23