B (programming language): Difference between revisions

Content deleted Content added
m hyperlink to programming language
Line 49:
Thompson added "two-address assignment operators" using <code>x =+ y</code> syntax to add y to x (in C the operator is written <code>+=</code>). This syntax came from [[Douglas McIlroy]]'s implementation of [[TMG (language)|TMG]], in which B's compiler was first implemented (and it came to TMG from [[ALGOL 68]]'s <code>x +:= y</code> syntax).<ref name=chist /><ref>{{cite web |author=Michael S. Mahoney |author-link=Michael Sean Mahoney |url=https://www.princeton.edu/~hos/mike/transcripts/mcilroy.htm |title=Interview with M.D. McIlroy |___location=Murray Hill |date=18 August 1989|website=Princeton.edu}}</ref> Thompson went further by inventing the increment and decrement operators (<code>++</code> and <code>--</code>). 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.<ref name=chist />
 
The semicolon version of the [[for loop]] was borrowed by Ken Thompson from the work of [[Stephen C. Johnson|Stephen Johnson]].<ref name="ken">{{cite web|title=VCF East 2019 -- Brian Kernighan interviews Ken Thompson| author=Ken Thompson| url=https://www.youtube.com/watch?v=EY6q5dv_B-o&t=2330 | archive-url=https://ghostarchive.org/varchive/youtube/20211123/EY6q5dv_B-o| archive-date=2021-11-23 | url-status=live|quote="I saw Johnson's semicolon version of the for loop and I put that in [B], I stole it." | access-date=2020-11-16}}{{cbignore}}</ref>
 
B is typeless, or more precisely has one data type: the computer word. Most operators (e.g. <code>+</code>, <code>-</code>, <code>*</code>, <code>/</code>) treated this as an integer, but others treated it as a memory address to be [[reference (computer science)|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 [[stdio.h|standard I/O library]] in C.<ref name=bur />