World Library  
Flag as Inappropriate
Email this Article

B (programming language)

Article Id: WHEBN0000004475
Reproduction Date:

Title: B (programming language)  
Author: World Heritage Encyclopedia
Language: English
Subject: BCPL, Bon (programming language), List of computer term etymologies, History of programming languages, Dennis Ritchie
Publisher: World Heritage Encyclopedia

B (programming language)

Designed by Ken Thompson
Developer Ken Thompson, Dennis Ritchie
First appeared 1969 (1969)[1]
Typing discipline typeless (everything is a word)
Filename extensions .b
Influenced by

B is a programming language developed at Bell Labs circa 1969. It is the work of Ken Thompson with Dennis Ritchie.

B was derived from BCPL, and its name may be a contraction of BCPL. Thompson's coworker Dennis Ritchie speculated that the name might be based on Bon, an earlier, but unrelated, programming language that Thompson designed for use on Multics.[note 1]

B was designed for recursive, non-numeric, machine independent applications, such as system and language software.[3]


Initially Ken Thompson[2] and later Dennis Ritchie[3] developed B basing it mainly on the BCPL language Thompson used in the Multics project. B was essentially the BCPL system stripped of any component Thompson felt he could do without in order to make it fit within the memory capacity of the minicomputers of the time. The BCPL to B transition also included changes made to suit Thompson's preferences (mostly along the lines of reducing the number of non-whitespace characters in a typical program).[2] Much of the typical ALGOL-like syntax of BCPL was rather heavily changed in this process, such as the := and = operators which were replaced with = for assignment and == for equality test. (The & and | of BCPL was later changed to && and || in the transition to what is now known as C.) [2] The assignment operator went back to "=" of Rutishauser's programming language Superplan, which had influenced ALGOL 58, that added a colon.

Thompson invented arithmetic assignment operators for B, using x =+ y to add y to x (in the C programming language the operator is spelled as +=). B also introduced the increment and decrement operators (++ and --); Their prefix or postfix position determines whether the value is taken prior or post alteration of the operand. These innovations were not in the earliest versions of B. Some guess that they were created for the auto-increment and auto-decrement address modes of the DEC PDP-11. This is historically impossible as there was no PDP-11 at the time that B was developed.[2]

B is typeless, or more precisely has one data type: the computer word. Most operators (e.g., +, -, *, /) treated this as an integer, but others treated it as a memory address to be dereferenced. In many other ways it looked a lot like an early version of C. There are a few library functions, including some that vaguely resemble functions from the standard I/O library in C.[3]

Early implementations were for the DEC PDP-7 and PDP-11 minicomputers using early Unix, and Honeywell GE 645[4] 36-bit mainframes running the operating system GCOS. The earliest PDP-7 implementations compiled to threaded code, and Ritchie wrote a compiler using TMG which produced machine code.[5][6][7] In 1970 a PDP-11 was acquired and threaded code was used for the port; an assembler, dc, and the B language itself were written in B to bootstrap the computer. An early version of yacc was produced with this PDP-11 configuration. Ritchie took over maintenance during this period.[2][7]

The typeless nature of B made sense on the Honeywell, PDP-7 and many older computers, but was a problem on the PDP-11 because it was difficult to elegantly access the character data type that the PDP-11 and most modern computers fully support. Starting in 1971 Ritchie made changes to the language while converting its compiler to produce machine code, most notably adding data typing for variables. During 1971 and 1972 B evolved into "New B" (NB) and then C.[2]

B is almost extinct, having been superseded by the C language.[8] However, it continues to see use (as of 2014) on GCOS mainframes,[9] and on certain embedded systems (as of 2000) for a variety of reasons, including limited hardware in the small systems; extensive libraries, tools, licensing cost issues; and simply being good enough for the job on others.[8] The highly influential AberMUD was originally written in B.


The following example is from the Users' Reference to B by Ken Thompson:[3]

/* The following function will print a non-negative number, n, to
   the base b, where 2<=b<=10.  This routine uses the fact that
   in the ASCII character set, the digits 0 to 9 have sequential
   code values.  */

printn(n, b) {
        extrn putchar;
        auto a;

        if (a = n / b)        /* assignment, not test for equality */
                printn(a, b); /* recursive */
        putchar(n % b + '0');

See also


  1. ^ "Its name most probably represents a contraction of BCPL, though an alternate theory holds that it derives from Bon [Thompson 69], an unrelated language created by Thompson during the Multics days. Bon in turn was named either after his wife Bonnie, or (according to an encyclopedia quotation in its manual), after a religion whose rituals involve the murmuring of magic formulas."[2]


  1. ^
  2. ^ a b c d e f g
  3. ^ a b c d
  4. ^
  5. ^
  6. ^
  7. ^ a b
  8. ^ a b
  9. ^

External links

  • Manual page for b(1) from Unix First Edition
  • The Development of the C Language, Dennis M. Ritchie. Puts B in the context of BCPL and C.
  • Users' Reference to B, Ken Thompson. Describes the PDP-11 version.
  • The Programming Language B, S. C. Johnson & B. W. Kernighan, Technical Report CS TR 8, Bell Labs (January 1973). The GCOS version on Honeywell equipment.
  • B Language Reference Manual, Thinkage Ltd. The production version of the language as used on GCOS, including language and runtime library.
This article was sourced from Creative Commons Attribution-ShareAlike License; additional terms may apply. World Heritage Encyclopedia content is assembled from numerous content providers, Open Access Publishing, and in compliance with The Fair Access to Science and Technology Research Act (FASTR), Wikimedia Foundation, Inc., Public Library of Science, The Encyclopedia of Life, Open Book Publishers (OBP), PubMed, U.S. National Library of Medicine, National Center for Biotechnology Information, U.S. National Library of Medicine, National Institutes of Health (NIH), U.S. Department of Health & Human Services, and, which sources content from all federal, state, local, tribal, and territorial government publication portals (.gov, .mil, .edu). Funding for and content contributors is made possible from the U.S. Congress, E-Government Act of 2002.
Crowd sourced content that is contributed to World Heritage Encyclopedia is peer reviewed and edited by our editorial staff to ensure quality scholarly research articles.
By using this site, you agree to the Terms of Use and Privacy Policy. World Heritage Encyclopedia™ is a registered trademark of the World Public Library Association, a non-profit organization.

Copyright © World Library Foundation. All rights reserved. eBooks from Project Gutenberg are sponsored by the World Library Foundation,
a 501c(4) Member's Support Non-Profit Organization, and is NOT affiliated with any governmental agency or department.