knowledge/c78
This commit is contained in:
parent
33f012d91c
commit
dd1a50de14
@ -84,6 +84,7 @@ I'm vaccinated against COVID-19. Are you?
|
|||||||
<A HREF="thegame" >/thegame</A>;
|
<A HREF="thegame" >/thegame</A>;
|
||||||
<B>knowledge</B>:
|
<B>knowledge</B>:
|
||||||
<A HREF="knowledge/cat/" >cat(1)</A>,
|
<A HREF="knowledge/cat/" >cat(1)</A>,
|
||||||
|
<A HREF="knowledge/c78" >c78</A>,
|
||||||
<A HREF="knowledge/software">software</A>,
|
<A HREF="knowledge/software">software</A>,
|
||||||
<A HREF="knowledge/true" >true(1)</A>,
|
<A HREF="knowledge/true" >true(1)</A>,
|
||||||
<A HREF="knowledge/x200t" >X200T</A>;
|
<A HREF="knowledge/x200t" >X200T</A>;
|
||||||
|
84
homepage/knowledge/c78.html
Normal file
84
homepage/knowledge/c78.html
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<HTML LANG="en">
|
||||||
|
<HEAD>
|
||||||
|
<LINK HREF="http://www.trinity.moe/knowledge/c78" REL="canonical" />
|
||||||
|
<LINK HREF="https://raw.githubusercontent.com/devenblake/homepage/main/favicon.ico" REL="shortcut icon" TYPE="image/x-icon" />
|
||||||
|
<LINK HREF="/css/blank.css" ID="styling" REL="stylesheet" />
|
||||||
|
<META CHARSET="UTF-8" />
|
||||||
|
<META CONTENT="noindex" NAME="googlebot" /> <!-- FUCK GOOGLE -->
|
||||||
|
<META CONTENT="interest-cohort=()" HTTP-EQUIV="Permissions-Policy" /> <!-- FUCK GOOGLE -->
|
||||||
|
<META NAME="viewport" CONTENT="width=device-width, initial-scale=1" />
|
||||||
|
<TITLE>K&R C</TITLE>
|
||||||
|
</HEAD>
|
||||||
|
<BODY>
|
||||||
|
<P><A HREF="/">~ Return to the rest of the site</A></P>
|
||||||
|
<SCRIPT SRC="/js/cookies.js" TYPE="application/javascript"></SCRIPT>
|
||||||
|
<SCRIPT SRC="/js/sheets.js" TYPE="application/javascript"></SCRIPT>
|
||||||
|
<SCRIPT TYPE="application/javascript">window.onload = window.initializesheets;</SCRIPT>
|
||||||
|
<H1>K&R C</H1>
|
||||||
|
<H3>updated 2022-05-29</H3>
|
||||||
|
<HR ALIGN="left" SIZE="1" WIDTH="25%" />
|
||||||
|
<UL>
|
||||||
|
<LI><A HREF="https://archive.org/details/TheCProgrammingLanguageFirstEdition">The C Programming Language, 1st ed.</A> (The Internet Archive)</LI>
|
||||||
|
<LI><A HREF="https://www.bell-labs.com/usr/dmr/www/cman.pdf">C Reference Manual</A> (this paper bears striking similarity to and was also written by the author of Appendix A of <I>The C Programming Language, 1st ed.</I> - the chronology of these writings' release is unknown)</LI>
|
||||||
|
<LI><A HREF="https://arstechnica.com/features/2020/12/a-damn-stupid-thing-to-do-the-origins-of-c/">"A damn stupid thing to do" - the origins of C</A></LI>
|
||||||
|
<LI><A HREF="https://www.bell-labs.com/usr/dmr/www/chist.html">The Development of the C Language</A></LI>
|
||||||
|
<LI><A HREF="http://pdp11.aiju.de/">PDP-11 Emulator</A></LI>
|
||||||
|
</UL>
|
||||||
|
<P>
|
||||||
|
The C programming language was first described to the public in <I>The C Programming Language</I> by Brian W. Kernighan and Dennis M. Ritchie, published by Prentice Hall in 1978.
|
||||||
|
The language evolved out of the former B programming language, which was a product of Ken Thompson:
|
||||||
|
</P>
|
||||||
|
<PRE>"""</PRE>
|
||||||
|
<P>Challenged by McIlroy's feat in reproducing TMG, Thompson decided that Unix—possibly it had not even been named yet—needed a system programming language. After a rapidly scuttled attempt at Fortran, he created instead a language of his own, which he called B. B can be thought of as C without types; more accurately, it is BCPL squeezed into 8K bytes of memory and filtered through Thompson's brain. 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.</P>
|
||||||
|
<PRE>""" (<I>The Development of the C Language</I>)</PRE>
|
||||||
|
<P>[Thompson 69] references <CODE>K. Thompson, `Bon—an Interactive Language,' undated AT&T Bell Laboratories internal memorandum (ca. 1969)</CODE>
|
||||||
|
- please get in touch if you have a hyperlink for this document as I can't find it indexed on any search engines.</P>
|
||||||
|
<P>
|
||||||
|
This language described in <I>The C Programming Language</I> isn't the C programming language known by most.
|
||||||
|
It was a pre-standardization, relatively prototypical C, and rather than being codified in ANSI its primary documentation was the book by Kernighan and Ritchie (this book would later be known colloquially as <I>K&R</I>).
|
||||||
|
This was known as "pre-ANSI C" or "K&R C" and dubbed "C78" for the purposes of naming this page, in the same style as the later "C89", described in ANSI X3.159-1989, or "C11", described in ISO/IEC 9899:2011.
|
||||||
|
"C78" was also the name given to historical C by the <CODE>c78(7)</CODE> manual page on FreeBSD 9.0.
|
||||||
|
</P>
|
||||||
|
<P>
|
||||||
|
"C78" is incompatible with "C89" and later standards.
|
||||||
|
This page documents those incompatibilities and relative oddities.
|
||||||
|
</P>
|
||||||
|
<P>
|
||||||
|
I have never done (and probably never will do) extensive programming in pre-ANSI C.
|
||||||
|
These incompatibilities were discovered out of Appendix C in <I>The C Programming Language, 2nd ed.</I> but are described further.
|
||||||
|
</P>
|
||||||
|
<H2><CODE>8</CODE> and <CODE>9</CODE> as valid octal digits</H2>
|
||||||
|
<PRE>
|
||||||
|
main()
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < 10; ++i)
|
||||||
|
printf("%c\t%o\n", i + '0', i);
|
||||||
|
}
|
||||||
|
</PRE>
|
||||||
|
<P>
|
||||||
|
In pre-ANSI C, <CODE>8</CODE> and <CODE>9</CODE> were valid octal digits corresponding to <CODE>10</CODE> and <CODE>11</CODE>.
|
||||||
|
This is documented in <I>The C Programming Language</I>, Appendix A, subsection 2.4.1, and evidenced by the preceding code block.
|
||||||
|
The following is output of the compiled program in UNIX V6 on an emulated PDP-11:
|
||||||
|
</P>
|
||||||
|
<PRE>
|
||||||
|
0 0
|
||||||
|
1 1
|
||||||
|
2 2
|
||||||
|
3 3
|
||||||
|
4 4
|
||||||
|
5 5
|
||||||
|
6 6
|
||||||
|
7 7
|
||||||
|
8 10
|
||||||
|
9 11
|
||||||
|
</PRE>
|
||||||
|
<P>
|
||||||
|
This behavior exists within <CODE>/usr/source/c/c0t.s</CODE>, which is a PDP-11 assembler file that parses integer constants (as far as I can tell).
|
||||||
|
This file provides <CODE>getnum</CODE>, a function used in <CODE>/usr/source/c/c00.c</CODE>.
|
||||||
|
My theory is that this behavior is a side-effect of a very efficient but imperfect method of parsing integer constants from a file stream,
|
||||||
|
and that this implementation was "good enough" and informally the behavior of a C compiler supplied invalid octal constants was just undefined.
|
||||||
|
</P>
|
||||||
|
</BODY>
|
||||||
|
</HTML>
|
Loading…
Reference in New Issue
Block a user