C strings suck!

utzoo!decvax!genrad!mit-eddi!smh utzoo!decvax!genrad!mit-eddi!smh
Wed May 11 10:15:15 AEST 1983


The followup by Lutz points obliquely to what I have always considered
one of the most important and wondrous features of C, and one that is
almost universally missed by casual evaluators of the language.  (See,
for instance, Pournelle's comments on C in Byte several months back.)

If you look very carefully at the de facto C language "standard" ---
the language K&R book --- you will observe the surprising fact that
C has absolutely no definition of input-output or even the notion
of a "main" procedure!  All these things are provided by the object-
time environment.  The ubiquitous presence of the standard io library
or something like it in most programs and manual examples tends to hide
this.  Ever wondered why the grammar, or at least, the keyword list for
C is so brief?

Why is this so important?  Obviously, it makes porting the language to
a new machine much easier, especially since most or even all of the
standard io library can be written in C.  Still, this hardly matters
to most users.  My intuition is that this *brilliant* feat of language
design has allowed C the language to be much more plastic in the face
of changing system interface needs.  It seems a large portion of language
gripes (e.g. with FORTRAN, and especially Pascal) have to do with io.
A change to the way io is done in most languages requires a ponderous
change to language specifications and new versions of the compiler.
Compare how much easier (relatively) was the standard io library change
which occurred between Unix 6 & 7.  Even today, useful new features
creep into the standard io library without much ado -- also without
much documentation, but let that pass!  Of course, the strategy of
packaging io inside called functions is available to other languages,
but often seems a "crock" and contrary to the "spirit" of those
languages.

Consider how easy it is, for example, to write C code to download to
stand-alone (non-Unix) processors.  I have done so using the standard
compiler, the standard ld, and even as much of the standard io library
as made sense on the target machine, without particular crockiness.
The only special code which had to be written was a modified lib/crt0.o
to setup a C stack environment, and the innermost io routines to poke
at device registers (putchar, for example).  The latter, of course,
were written in C!  I suspect the project would have been much more
involved using a language carrying its own idea of io, but perhaps I
am wrong...

There must be other languages out there wth this "feature", but I
can't think of one offhand.  I will point out in passing how analagous
this aspect of C is to the PDP11 processor, which also lacks any
io instructions.  I wonder if there is any conscious or unconscious
causal relation.

Sorry about the length of this followup.  Any further remarks should
probably be posted to net.lang or net.lang.c .

					Steve Haflich
					MIT Experimental Music Studio
					...!genrad!mit-eddie!smh




More information about the Comp.lang.c mailing list