BCPL to B to C: other articles by Mark Brader, Clive Feather, and Dennis Ritchie
From: alan@oldp.astro.wisc.edu (Alan Watson)
Newsgroups: comp.lang.c
Subject: Re: int main() (was SUMMARY: CW poll: exit vs. return)
Date: 6 Sep 1993 06:50:21 GMT
Organization: University of Wisconsin - Astronomy Department
Message-ID: <26emjd$jhe@news.doit.wisc.edu>

In article <26doorINNqvl@umbc7.umbc.edu> schlein@umbc.edu (Jonas Schlein) wrote:
>Tell me more about this predecessor language. From the rest of the post which
>was deleted it seems that this 'B' was even worse than old-style C on
>type-checking.

During the early 1960s, CPL (Cambridge, or Combined, Programming Language) which was jointly designed by people from the Computer Lab at Cambridge University and people from London University.  It was somewhat like Ada in scope, supposedly all things to all problems, and I'm not sure it was ever fully implemented.

In the late 1960s, Martin Richards, while at Cambridge, implemented a simplified version of CPL called Basic CPL or BCPL on the 370.  Objects are typeless in BCPL, in as much as their type is inferred from the context in which they are used (i.e., in a redirection context an object is assumed to be an address, and in an arithmetic it is assumed to be a signed integer).  BCPL is similar to C in that is all arguments are passed by value, although the language tokens are much more wordy than C and is has local functions.  Character escapes in BCPL strings are denoted by, for example, "*N" for newline. 

As an illustration, the following programs prints the factorials of the first 10 natural numbers:

   // FACTORIAL
   GET "LIBHDR"
   LET START () BE $(
      LET F(N) = N=0 -> 1, N*F(N-1)
      FOR I = 1 TO 10 DO WRITEF("F(%N), = %N*N", I, F(I))
      FINISH 
   $)

Translated into very old C, this is:

   /* Factorial */
   #include <stdio.h>
   static f(n) /* in the BCPL version, this was local to main */
   {
      return n == 0 ? 1 : n*f(n-1);
   }
   main()
   {
      auto i;
      for (i = 1; i <= 10; i++)
	 printf("f(%d), = %d\n", i, f(i));
      return 0;
   }

Note that comments in BCPL begin with // and end with newline, like those in C++.  Further trivia is that on IBM mainframes (or at least those running Phoenix),
"/*" serves the same purpose as ctrl-d on a Unix system -- it terminates input from the terminal.  Was the adoption of this as a comment delimiter an inside joke by Ritchie?

BCPL is described in the book  `BCPL: The Language and Its Compiler'  by Martin Richards and Colin Whitby-Strevens, which also includes the full source code for a portable compiler for BCPL.  The book is interesting not just from the point of view of the language, but also because it provides a view of compiler technology and approaches to program portability in the late 60s and early 70s. I would recommend checking this book out of the library. 

BCPL was in use in Cambridge for years.  Much of the software for the Phoenix system (layered over MVT and then MVS on the IBM 3081s and 3084s at Cambridge and London) was written in BCPL (most of the rest was in assembler, although Algol68 was used for a mailer and the infamous job scheduler -- I think there must be something in the water in Cambridge).  BCPL was still in use as recently as the late 1980s, when it was used to implement a portable full-screen editor.  In the late 1980s, the Computer Lab obtained a C compiler for the 370 and wrote a C library for MVS, and C usurped BCPL even in its home environment.

At some point early in BCPL's life, Richards brought his compiler over the pond, I believe to either MIT or Bell Labs.  Ritchie obviously spent some time studying the language (he is given joint credit for a summary of the language, which forms the basis for an appendix to Richards and Whitby-Strevens), and was impressed by the concept of a portable, high-level language.  He designed and implemented B, which has been described as a typeless version of C.

And here I'm going to stop.  Someone who knows more about B can continue In particular, I am interested in why Ritchie chose to reform BCPL into B -- the semantics seem very similar (other than scope and linkage issues), but the syntax and tokens are very different.  Does it come down to the speed of terminal technology at that time?  I think the BCPL grammar and lexical structure is a mess, but I came to it after learning C, so I am not really in a position to give an unbiased opinion.


BCPL to B to C: other articles by Mark Brader, Clive Feather, and Dennis Ritchie