Share to: share facebook share twitter share wa share telegram print page

B (programming language)

B
Designed byKen Thompson
DeveloperKen Thompson, Dennis Ritchie
First appeared1969; 55 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 Labs, 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.

History

BCPL semantics with a lot of SMALGOL syntax

— Ken Thompson, [4]

Circa 1969, 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. The assignment operator := reverted to the = of Rutishauser's Superplan, and the equality operator = was replaced by ==.

Thompson added "two-address assignment operators" using x =+ y syntax to add y to x (in C the operator is written +=). This syntax came from Douglas McIlroy's implementation of TMG, in which B's compiler was first implemented (and it came to TMG from ALGOL 68's x +:= y syntax).[2][5] Thompson went further by inventing the increment and decrement operators (++ and --). Their prefix or postfix position determines whether the value is taken before or after alteration of the operand. This innovation was not in the earliest versions of B. According to Dennis Ritchie, people often assumed that they were created for the auto-increment and auto-decrement address modes of the DEC PDP-11, but this is historically impossible as the machine didn't exist when B was first developed.[2]

The semicolon version of the for loop was borrowed by Ken Thompson from the work of Stephen Johnson.[6]

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] In Thompson's words: "B and the old old C were very very similar languages except for all the types [in C]".[6]

Early implementations were for the DEC PDP-7 and PDP-11 minicomputers using early Unix, and Honeywell GE 645[7] 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.[8][9][10] 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][10]

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.[11] However, it continues to see use on GCOS mainframes (as of 2014)[12] and on certain embedded systems (as of 2000) for a variety of reasons: limited hardware in small systems, extensive libraries, tooling, licensing cost issues, and simply being good enough for the job.[11] The highly influential AberMUD was originally written in B.

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 ANSCII 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 conver-
   sion 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;

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. ^ a b c d e f g 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 c d 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.
  4. ^ Jensen, Richard (9 December 2020). ""A damn stupid thing to do"—the origins of C". Ars Technica. Retrieved 2022-03-28.
  5. ^ Michael S. Mahoney (18 August 1989). "Interview with M.D. McIlroy". Princeton.edu. Murray Hill.
  6. ^ a b Ken Thompson. "VCF East 2019 -- Brian Kernighan interviews Ken Thompson". YouTube. Archived from the original on 2021-11-23. Retrieved 2020-11-16. I saw Johnson's semicolon version of the for loop and I put that in [B], I stole it.
  7. ^ Ritchie, Dennis M. (1984). "The Evolution of the Unix Time-sharing System". AT&T Bell Laboratories Technical Journal. 63 (6 Part 2): 1577–1593. doi:10.1002/j.1538-7305.1984.tb00054.x. Archived from the original on 11 June 2015.
  8. ^ "TMG". multicians.org.
  9. ^ Ritchie, Dennis M. "The Development of the C Language". Bell Labs/Lucent Technologies. Archived from the original on 11 June 2015.
  10. ^ a b McIlroy, M. D. (1987). A Research Unix reader: annotated excerpts from the Programmer's Manual, 1971–1986 (PDF) (Technical report). CSTR. Bell Labs. 139. Archived (PDF) from the original on 2022-10-09.
  11. ^ a b Johnson and Kernighan. "THE PROGRAMMING LANGUAGE B". Bell Laboratories. Archived from the original on 11 June 2015. Retrieved 21 March 2014.
  12. ^ "Thinkage UW Tools Package". Thinkage, Ltd. Retrieved 26 March 2014.

Read other articles:

奈良県立郡山高等学校 北緯34度38分59.7秒 東経135度46分47.4秒 / 北緯34.649917度 東経135.779833度 / 34.649917; 135.779833座標: 北緯34度38分59.7秒 東経135度46分47.4秒 / 北緯34.649917度 東経135.779833度 / 34.649917; 135.779833過去の名称 奈良縣立郡山中學校奈良縣尋常中學校奈良縣郡山尋常中學校大阪府立郡山中學校大阪府立堺師範學校分校郡山學校堺県師範學...

Гедда Ціннернім. Hedda Zinner Гедда Ціннер. Лейпциґ, 1948.Псевдонім нім. Elisabeth Frank, Hannchen Lobesam, Hedda (Елізабет Франк, Ганнхен Лобезам, Гедда)Народилася 20 травня 1905(1905-05-20)ЛьвівПомерла 4 липня 1994(1994-07-04) (89 років)Берлін. Похована на Доротеєнштадтському кладовищі (Берлін)Поховання Доротеен...

Vista de la bahía de Málaga desde el monte San Antón. El área metropolitana de Málaga es la región urbana que engloba a la ciudad andaluza que le da nombre y a una serie de poblaciones satélites que funcionan como ciudades dormitorio, industriales, comerciales y de servicios. El espacio metropolitano de Málaga responde al modelo clásico de ciudad central dominante, que ha alcanzado un importante grado de complejidad y se encuentra en un ciclo de proceso metropolitano en el que la ciu...

Universitas Negeri MedanNama sebelumnyaInstitut Keguruan dan Ilmu Pendidikan Medan (IKIP Medan)MotoThe Character Building UniversityMoto dalam bahasa IndonesiaUniversitas Pembangunan KarakteJenisPerguruan Tinggi NegeriDidirikan23 Juni 1963; 60 tahun lalu (1963-06-23)Lembaga indukKementerian Pendidikan, Kebudayaan, Riset, dan TeknologiRektorProf. Dr. Baharuddin, ST., M. Pd.KampusUrbanNama julukanUnimed Universitas Negeri Medan (disingkat UNIMED) adalah salah satu perguruan tinggi neg...

For other uses, see Samata Party (disambiguation). Political party in India Indian political party Rashtriya Lok Samata Party AbbreviationRLSPPresidentUpendra KushwahaFounderUpendra KushwahaFounded3 March 2013 (10 years ago) (2013-03-03)Dissolved14 March 2021 (2 years ago) (2021-03-14)Split fromJanata Dal (United)Merged intoJanata Dal (United)ECI StatusState PartyAllianceNational Democratic Alliance (2014—2018) United Progressive Alliance (2018—2020)G...

هذه المقالة بحاجة لصندوق معلومات. فضلًا ساعد في تحسين هذه المقالة بإضافة صندوق معلومات مخصص إليها. اليوبيل الذهبي لدوري الاستطلاع هو الاسم الشعبي للاستطلاع على الإنترنت الذي أجري في عام 2004 من قبل الاتحاد الأوروبي في إطار الاحتفالات باليوبيل الذهبي لها، تحتفل بأفضل لاعبي ...

Upcoming 2023 video game 2023 video gameThe Day BeforeSteam headerDeveloper(s)FntasticPublisher(s)MytonaEngineUnreal Engine 5Platform(s)WindowsRelease7 December 2023 (Early Access)Genre(s)Survival horror, open worldMode(s)Multiplayer The Day Before is an upcoming multiplayer open world survival horror video game developed by Fntastic and published by Mytona. Plot Set in a post-apocalyptic version of the United States, the world has been overrun by zombies after a pandemic.[1] Developm...

Australian biographical dictionary Not to be confused with Dictionary of Australian Biography. Australian Dictionary of Biography First edition of volume 1CountryAustraliaLanguageEnglishSubjectBiographies of notable AustraliansGenreEncyclopediaPublishedCarlton, VictoriaPublisherMelbourne University PressPublication date1966–2012Media typeHard copyISBN978-0-522-84459-7Websiteadb.anu.edu.au The Australian Dictionary of Biography (ADB or AuDB) is a national co-operative enterprise founded...

У этого термина существуют и другие значения, см. Слепое пятно (значения). Слепое пятно правого глаза — на фотографии глазного дна светлое пятно справа (расположено медиально). Более тёмное на снимке пятно левее — макула (жёлтое пятно) На периметрической карточке пр...

Este artículo o sección necesita referencias que aparezcan en una publicación acreditada.Este aviso fue puesto el 27 de enero de 2013. Ermita de Santo Tomé LocalizaciónPaís España EspañaComunidad Extremadura ExtremaduraProvincia Cáceres CáceresLocalidad PlasenciaCoordenadas 40°01′36″N 6°05′34″O / 40.0266793, -6.0927709Información religiosaDiócesis Diócesis de Plasencia[editar datos en Wikidata] Interior La ermita de Santo Tomé e...

German chemist (1879–1968) For the petrologist, see Otto Hahn (petrologist). For the nuclear-powered merchant vessel, see Otto Hahn (ship). Otto HahnBorn(1879-03-08)8 March 1879Frankfurt am Main, Hesse-Nassau, Prussia, German Empire (now Germany)Died28 July 1968(1968-07-28) (aged 89)Göttingen, West Germany (now Germany)Alma mater University of Marburg University of Munich Known for Discovery of radioactive elements (1905–1921) Radiothorium (228Th, 1905) Radioactinium ...

1986 film by David Anspaugh HoosiersTheatrical release posterDirected byDavid AnspaughWritten byAngelo PizzoProduced byCarter De HavenAngelo PizzoStarring Gene Hackman Barbara Hershey Dennis Hopper CinematographyFred MurphyEdited byCarroll Timothy O'MearaMusic byJerry GoldsmithProductioncompaniesHemdale PicturesDe Haven ProductionsDistributed byOrion PicturesRelease date November 14, 1986 (1986-11-14) Running time115 minutesCountryUnited StatesLanguageEnglishBudget$6 million ...

1941–1945 occupation of British Borneo by Japan For the occupation in West Malaysia, see Japanese occupation of Malaya. Japanese-occupied British Borneo (British North Borneo, Brunei, Labuan and Sarawak)North Borneo (北ボルネオ, Kita Boruneo)1941–1945 Flag of the Empire of Japan Imperial Seal Motto: Eight Crown Cords, One Roof (八紘一宇, Hakkō Ichiu)Anthem: Kimigayo Japanese possessions in Borneo in 1943StatusMilitary occupation by the Empire of JapanCapitalKuching[...

Depressão Tropical Um Tempestade tropical (SSHWS/NWS) A depressão tropical Um a 28 de maio. Formação 28 Dissipação 29 de maio de 2009 Ventos mais fortes sustentado 10 min.: 75 km/h (45 mph) sustentado 1 min.: 65 km/h (40 mph) Pressão mais baixa 1006 mbar (hPa); 29.71 inHg Fatalidades Nenhum Danos Nenhum Áreas afectadas Costas da Carolina do Norte Parte da Temporada de furacões no oceano Atlântico de 2009 editar  A Depressão Tropical Um foi o primeiro ciclone tropical a se ...

Canadian children's music group Sharon, Lois & BramSharon, Lois & Bram with Elephant in 1994Background informationOriginToronto, Ontario, CanadaGenresChildren's musicInstrument(s)Sharon: vocals, guitar, piano, tambourineLois: piano, autoharp, vocalsBram: guitar, banjo, vocalsYears active1978 (1978)–present (present)LabelsElephant, A&M, Drive Entertainment, Skinnamarink Entertainment, Casablanca Kids Inc.MembersSharon HampsonRandi HampsonPast membersLois Lilienstein Bra...

Australian actress This biography of a living person needs additional citations for verification. Please help by adding reliable sources. Contentious material about living persons that is unsourced or poorly sourced must be removed immediately from the article and its talk page, especially if potentially libelous.Find sources: Noni Hazlehurst – news · newspapers · books · scholar · JSTOR (May 2022) (Learn how and when to remove this template message) N...

This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Secret Heart Beat – news · newspapers · books · scholar · JSTOR (October 2021) (Learn how and when to remove this template message) 2002 Burmese filmSecret Heart BeatSecret Heart Beat's VCD released posterDirected byMa Li Kha Soe Htike AungScreenplay byKo Ko La...

Strike Witches ストライクウィッチーズ(Сутораику Виттидзу)Штурмовые ведьмыЖанр / тематикаприключения, фантастика, этти Манга «Strike Witches Sōkū no Otome-tachi» Автор Ёсиюки Кадзуми Издатель Kadokawa Shoten Публикуется в Comp Ace Аудитория сэйнэн Публикация 2005 год — 2006 год Томов 2 (отменён) Ранобэ «Strike Wi...

Waukesha, Wisconsin kotasecond-class city (en) pusat county Tempat Negara berdaulatAmerika SerikatNegara bagian di Amerika SerikatWisconsinCounty of Wisconsin (en) County Waukesha Ibu kota dariCounty Waukesha NegaraAmerika Serikat PendudukTotal71.158  (2020 )Tempat tinggal29.704  (2020 )GeografiLuas wilayah66,557523 km² [convert: unit tak dikenal]• Air1,0188 % Ketinggian271 m Berbatasan denganPewaukee (en) SejarahPembuatan1834 Informasi tambahanKode pos53188 Zo...

Ski and snowboard resort in Pennsylvania This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Camelback Mountain Resort – news · newspapers · books · scholar · JSTOR (January 2022) (Learn how and when to remove this template message) This article is about the Pocono ski resort. For the mountain in Arizona, see Ca...

Kembali kehalaman sebelumnya