Sunday, December 12, 2010

                                  Development of C
Ritchie

More History
After the TMG version of B was working, Thompson rewrote B in itself (a bootstrapping
step). During development, he continually struggled against memory limitations: each language
addition inflated the compiler so it could barely fit, but each rewrite taking advantage of the feature
reduced its size. For example, B introduced generalized assignment operators, using
x=+y
to add
it into his version of TMG. (In B and early C, the operator was spelled
this mistake, repaired in 1976, was induced by a seductively easy way of handling the first form
in B’s lexical analyzer.)
Thompson went a step further by inventing the
which increment or
decrement; their prefix or postfix position determines whether the alteration occurs before or after
noting the value of the operand. They were not in the earliest versions of B, but appeared along
the way. People often guess that they were created to use the autoincrement
and autodecrement
address modes provided by the DEC PDP11
on which C and Unix first became popular. This is
historically impossible, since there was no PDP11
when B was developed. The PDP7,
however,
did have a few ‘autoincrement’
memory cells, with the property that an indirect memory reference
through them incremented the cell. This feature probably suggested such operators to
Thompson; the generalization to make them both prefix and postfix was his own. Indeed, the
autoincrement
cells were not used directly in implementation of the operators, and a stronger
motivation for the innovation was probably his observation that the translation of
smaller than that of
The B compiler on the PDP7
did not generate machine instructions, but instead ‘threaded
code’ [Bell 72], an interpretive scheme in which the compiler’s output consists of a sequence of
addresses of code fragments that perform the elementary operations. The operations typically
particular for B
On the PDP7
Unix system, only a few things were written in B except B itself, because the
machine was too small and too slow to do more than experiment; rewriting the operating system
and the utilities wholly into B was too expensive a step to seem feasible. At some point Thompson
relieved the addressspace
crunch by offering a ‘virtual B’ compiler that allowed the interpreted
program to occupy more than 8K bytes by paging the code and data within the interpreter,
but it was too slow to be practical for the common utilities. Still, some utilities written in B
appeared, including an early version of the variableprecision
calculator
[McIlroy 79]. The most ambitious enterprise I undertook was a genuine crosscompiler
that
translated B to GE635
machine instructions, not threaded code. It was a small
full B compiler, written in its own language and generating code for a 36bit
mainframe, that ran
on an 18bit
machine with 4K words of user address space. This project was possible only
because of the simplicity of the B language and its runtime
system.
Although we entertained occasional thoughts about implementing one of the major languages
of the time like Fortran, PL/I, or Algol 68, such a project seemed hopelessly large for our
resources: much simpler and smaller tools were called for. All these languages influenced our
work, but it was more fun to do things on our own.
By 1970, the Unix project had shown enough promise that we were able to acquire the new
DEC PDP11.
The processor was among the first of its line delivered by DEC, and three months
passed before its disk arrived. Making B programs run on it using the threaded technique
required only writing the code fragments for the operators, and a simple assembler which I coded
in B; soon,
our PDP11.
Almost as rapidly, still waiting for the disk, Thompson recoded the Unix kernel and
some basic commands in PDP11
assembly language. Of the 24K bytes of memory on the
machine, the earliest PDP11
Unix system used 12K bytes for the operating system, a tiny space
for user programs, and the remainder as a RAM disk. This version was only for testing, not for
real work; the machine marked time by enumerating closed knight’s tours on chess boards of various
sizes. Once its disk appeared, we quickly migrated to it after transliterating assemblylanguage
commands to the PDP11
dialect, and porting those already in B.
y to x. The notation came from Algol 68 [Wijngaarden 75] via McIlroy, who had incorporated=+ instead of += ;++ and operators,++x wasx=x+1. in act on a simple stack machine.dc familiar to Unix userstour de force: adc became the first interesting program to be tested, before any operating system, on

No comments:

Post a Comment

THE WORLD NEW TECHNOLOGY