Ritchie
but ornamented it by placing its type keywords at the start of declarations.
Not every difference between the BCPL language documented in Richards’s book [Richards
79] and B was deliberate; we started from an earlier version of BCPL [Richards 67]. For example,
the
when we learned it in the 1960s, and so the overloading of the
from the B and C
In contrast to the pervasive syntax variation that occurred during the creation of B, the core
semantic content of BCPL
Both languages are typeless, or rather have a single data type, the ‘word,’ or ‘cell,’ a fixedlength
bit pattern. Memory in these languages consists of a linear array of such cells, and the meaning
of the contents of a cell depends on the operation applied. The
adds its operands using the machine’s integer add instruction, and the other arithmetic operations
are equally unconscious of the actual meaning of their operands. Because memory is a linear
array, it is possible to interpret the value in a cell as an index in this array, and BCPL supplies an
operator for this purpose. In the original language it was spelled
unary
endcase that escapes from a BCPL switchon statement was not present in the languagebreak keyword to escapeswitch statement owes to divergent evolution rather than conscious change. its type structure and expression evaluation rules remained intact.+ operator, for example, simplyrv, and later !, while B uses the*. Thus, if p is a cell containing the index of (or address of, or pointer to) another cell, *prefers to the contents of the pointedto
cell, either as a value in an expression or as the target of an
assignment.
Because pointers in BCPL and B are merely integer indices in the memory array, arithmetic
on them is meaningful: if
convention is the basis for the semantics of arrays in both languages. When in BCPL one writes
p is the address of a cell, then p+1 is the address of the next cell. Thislet V = vec 10
or in B,
auto V[10];
the effect is the same: a cell named
aside, and the memory index of the first of these is placed into
expression
V is allocated, then another group of 10 contiguous cells is setV. By a general rule, in B the*(V+i)
adds
location after
to sweeten such array accesses; in B an equivalent expression is
V and i, and refers to the ithV. Both BCPL and B each add special notationV[i]
and in BCPL
V!i
This approach to arrays was unusual even at the time; C would later assimilate it in an even less
conventional way.
None of BCPL, B, or C supports character data strongly in the language; each treats strings
much like vectors of integers and supplements general rules by a few conventions. In both BCPL
and B a string literal denotes the address of a static area initialized with the characters of the
string, packed into cells. In BCPL, the first packed byte contains the number of characters in the
string; in B, there is no count and strings are terminated by a special character, which B spelled
‘
holding the count in an 8or
9bit
slot, and partly because maintaining the count seemed, in our
experience, less convenient than using a terminator.
Individual characters in a BCPL string were usually manipulated by spreading the string out
into another array, one character per cell, and then repacking it later; B provided corresponding
routines, but peAople more often used other library functions that accessed or replaced individual
characters in a string.*e’. This change was made partially to avoid the limitation on the length of a string caused by
No comments:
Post a Comment
THE WORLD NEW TECHNOLOGY