Jump to content

B (programming language)

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by 14.99.186.154 (talk) at 07:36, 10 August 2022 (History). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
B
Designed byKen Thompson
DeveloperKen Thompson, Dennis Ritchie
First appeared1969; 56 years ago (1969)[1]
Typing disciplinetypeless (everything is a word)
Filename extensions.b
Influenced by
BCPL, PL/I, TMG
Influenced
C

B is a programming language developed at Bell Labs circa 1969 by Ken Thompson and Dennis Ritchie.

B was derived from BCPL, and its name may possibly 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] It was a typeless language, with the only data type being the underlying machine's natural memory word format, whatever that might be. Depending on the context, the word was treated either as an integer or a memory address.

As machines with ASCII processing became common, notably the DEC PDP-11 that arrived at Bell, support for character data stuffed in memory words became important. The typeless nature of the language was seen as a disadvantage, which led Thompson and Ritchie to develop an expanded version of the language supporting new internal and user-defined types, which became the C programming language.

Examples

The following examples are 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;
        /* Wikipedia note: the auto keyword declares a variable with
           automatic storage (lifetime is function scope), not
           "automatic typing" as in C++11. */

        if (a = n / b)        /* assignment, not test for equality */
                printn(a, b); /* recursive */
        putchar(n % b + '0');
}
/* The following program will calculate the constant e-2 to about
   4000 decimal digits, and print it 50 characters to the line in
   groups of 5 characters.  The method is simple output conversion
   of the expansion
     1/2! + 1/3! + ... = .111....
   where the bases of the digits are 2, 3, 4, . . . */

main() {
	extrn putchar, n, v;
	auto i, c, col, a;

	i = col = 0;
	while(i<n)
		v[i++] = 1;
	while(col<2*n) {
		a = n+1;
		c = i = 0;
		while (i<n) {
			c =+ v[i] *10;
			v[i++]  = c%a;
			c =/ a--;
		}

		putchar(c+'0');
		if(!(++col%5))
			putchar(col%50?' ': '*n');
	}
	putchar('*n*n');
}
v[2000];
n 2000;

See also

icon Computer programming portal

Notes

  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]

References

  1. ^ "B - computer programming language".
  2. ^ Ritchie, Dennis M. (March 1993). "The Development of the C Language". ACM SIGPLAN Notices. 28 (3): 201–208. doi:10.1145/155360.155580.
  3. ^ a b Thompson, Ken (7 January 1972). "Users' Reference to B" (PDF). Bell Laboratories. Archived from the original (PDF) on 17 March 2015. Retrieved 21 March 2014.