B is the programming language Ken Thompson created at Bell Labs around 1969, with help from Dennis Ritchie, for the first versions of Unix. It was a compact, typeless descendant of Martin Richards' BCPL, built to fit on a DEC PDP-7 with only a few thousand words of memory. If you are asking what was the B programming language used for, the short answer is: early Unix tools, the B compiler itself, and a few years of experiments that turned into C.
Origins: Unix on a PDP-7
In 1969, Bell Labs pulled out of the Multics project. Thompson, who had worked on Multics, began writing a new, simpler operating system on a little-used PDP-7. The first Unix was written in assembly language. Thompson wanted a higher-level language for writing system utilities, and his first idea was a Fortran compiler. That plan changed quickly, and what emerged was a language heavily based on BCPL.
BCPL itself was too large for the PDP-7, so Thompson squeezed it down. Ritchie later wrote that the name B was probably a contraction of BCPL, though another theory connects it to Bon, an earlier language Thompson had written.
Design and key features
- Typeless. Like BCPL, every value was a machine word. Its meaning depended on how you used it.
- Terse syntax. Thompson replaced BCPL's keywords and section brackets with shorter symbols and braces. B code already looks very much like early C.
- New operators. B introduced
++and--, and assignment operators written=+and=-, which C later reversed to+=and-=. - Storage classes.
autodeclared local variables andextrnreferred to global ones, words that survived in C asautoandextern. - Threaded code. The PDP-7 and early PDP-11 compilers produced threaded code that a small run-time interpreted, which was compact but slow.
A short B example
This is the well-known example from Brian Kernighan's tutorial on B, written in the early 1970s and widely cited as the origin of the "hello, world" program:
main( ) {
extrn a, b, c;
putchar(a); putchar(b); putchar(c); putchar('!*n');
}
a 'hell';
b 'o, w';
c 'orld';
Each external variable holds up to four characters packed into one word, which worked on the 36-bit Honeywell machines the tutorial targeted. The *n escape for newline came from BCPL.
What was the B programming language used for?
B had a short but important working life:
- Unix utilities. A few early Unix programs were written in B, though the kernel stayed in assembly.
- The B compiler. B was self-hosting, so the compiler was written in B.
- Honeywell systems. A version ran on Honeywell mainframes under the GCOS operating system, used at Bell Labs and at some universities, which is where Kernighan's tutorial examples came from.
- Language experiments. Thompson and Ritchie used B to test ideas that later shaped C.
Why B turned into C
In 1970 and 1971, Unix moved to the new PDP-11. Unlike the PDP-7, the PDP-11 addressed individual bytes and soon had floating-point hardware. A language with a single word type handled characters and floats awkwardly, and the threaded-code compiler was slow. Ritchie began adding types, first in a version he called NB ("New B"), and then in C, which appeared around 1972 with char, int and later struct. In 1973, the Unix kernel was rewritten in C, and B was quickly retired at Bell Labs.
| Year (approx.) | Event |
|---|---|
| 1969 | Thompson creates B on the PDP-7 |
| 1970–71 | B moves to the PDP-11 with Unix |
| 1971–72 | Ritchie's NB adds types |
| 1972 | C appears |
| 1973 | Unix kernel rewritten in C |
Influence and legacy
B's influence runs almost entirely through C, but that is enough to reach most of modern computing. The braces, the ++ operator, the terse expression style and the habit of treating memory as addressable words all passed from B to C, and from C to C++, Java, JavaScript, C#, Go and many others.
Is B still used today?
No. B is a historical language with no practical use today, although hobbyists have written B compilers and interpreters for modern systems to explore it. Knowing what was the B programming language used for, mainly bootstrapping early Unix and serving as a stepping stone, helps explain many of C's quirks, from its weak typing to its terse operators.
Frequently asked questions
Who created the B programming language?
Ken Thompson created B at Bell Labs around 1969, with contributions from Dennis Ritchie. It was based on Martin Richards' BCPL. Ritchie later evolved B into C.
Why was B replaced by C?
B had only one data type, the machine word, which suited the PDP-7 but not the byte-addressed PDP-11. It could not easily handle characters, floating point or structures, and its compiler produced slow threaded code. C added types and generated efficient machine code.
Was Unix written in B?
Not the kernel. Early Unix was written in assembly language, and B was used for some utilities. The kernel was rewritten in C in 1973, which made Unix much easier to port.







