8 ms·
I learnt C, more than 20 years ago, from the book The C Programming Language written by Brian W. Kernighan and Dennis M. Ritchie, also known as K&R. I read the
by susam 4y ago
I learnt C, more than 20 years ago, from the book The C Programming Language written by Brian W. Kernighan and Dennis M. Ritchie, also known as K&R. I read the book almost cover to cover all the way from the preface at the beginning to its three appendices at the end while solving all the exercises that each chapter presented. As someone who knew very little about programming languages back then, this book was formative in my journey of becoming a programmer.
Appendix A (Reference Manual) of the book broadened my outlook on programming languages by providing me a glimpse of what goes into formally specifying a programming language. Section A.12 (Preprocessing) of this appendix specifies trigraph sequences. Quoting from the section:
> Preprocessing itself takes place in several logically successive phases that may, in a particular implementation, be condensed.
> 1. First, trigraph sequences as described in Par.A.12.1 are replaced by their equivalents. Should the operating system environment require it, newline characters are introduced between the lines of the source file.
Then section A.12.1 (Trigraph Sequences) further elaborates trigraph sequences in more detail. Quoting this section below:
> The character set of C source programs is contained within seven-bit ASCII, but is a superset of the ISO 646-1983 Invariant Code Set. In order to enable programs to be represented in the reduced set, all occurrences of the following trigraph sequences are replaced by the corresponding single character. This replacement occurs before any other processing.
??= #
??/ \
??' ^
??( [
??) ]
??! |
??< {
??> }
??- ~
> No other such replacements occur.
> Trigraph sequences are new with the ANSI standard.
- Taniwha 4y agoThis is because IBM 029 card punches don't support these characters right?
- aidenn0 4y agoI thought it was because of international character sets that lacked the punctuation of EBCDIC CP37 or ASCII. [edit] For example ISO/IEC 646 is ascii with punctuation replaced by other characters.
- sargstuff 4y agostills leaves the issue of how to print out something that doesn't exist as a physical old style physical type face character. (way pre-dot matrix / laster printer stuff). -- aka substituting 3 characters way more informative than blank space.
- aidenn0 4y agoMy (possibly wrong) understanding is that trigraphs were a late addition to the ANSI standard, which would place it in late 80s, well into the CRT terminal and dot-matrix era.
- Taniwha 4y agoEBCDIC is very much IBM - on our old Burroughs machine we used to have to use cent signs (and something else that I forget) for square brackets and a 3-hole multipunch for ';'
- deleted 4y ago[deleted]
- wglb 4y agoOr an ASR33
- dragonwriter 4y agoI think the ISO/IEC 646 invariant character set is more the issue.
- randomswede 4y agoIn the "Swedish 7-bit ASCII", the C code "a || b" would look like "a öö b". The same character mappings were used in Finland, and that's why IRC count the characters {|}[\] as letters (that would typically have been displayed as "äöåÄÖÅ"). On the Compis II computer (a CP/M machine built on the 80186 CPU), there were places for {|}[\] in the character set, but they were in the top half of the 8-bit characters and not generally useful for programming.
- vonwoodson 4y agoTo be fair, and definitely a part of its appeal, the K&R is only 312 pages long. It covers the language and most of the standard library you’ll need. As opposed to say, “Learn You a Haskell for Great Good! A Beginner's Guide” which is 881 pages and doesn’t even moderately cover the prelude. Anyway, C is an amazing language and I keep a K&R on my phone as a pdf
- 1-more 4y agoMy copy of Learn You a Haskell ends on page 360 and the index is another 16 pages. Is this some weirdly shaped PDF of it with tiny phone-sized pages?
- sli 4y agoAccording to its listing on the No Starch website[0], the PDF is (currently) 400 pages. I'm not a fan of that particular Haskell book but it's in no way even close to 881 pages. [0]: https://nostarch.com/lyah.htm https://nostarch.com/lyah.htm
- b112 4y agoThat's 800 pages double sided! Simply because the back side is blank, is no reason to nitpick.
- tremon 4y agoI don't get it. Wouldn't 800 pages double-sided require a PDF containing 1600 pages?
- b112 4y agoSorry, been looking at new cars, and salespeople have been explaining new car, extended warranties to me.
- stonemetal12 4y ago400 single sided printed pages. If you are trying to inflate the page count that is 800 pages, but every other page is blank.
- kjs3 4y agoI, too, learned C by reading K&R cover to cover and solving all the exercises (in front of a Sun 3/160 running SunOS 3.5-ish). Even then back in those ancient days, it was obvious trigraphs were evil and should have been abolished to a special place in hell.
- deleted 4y ago[deleted]
- unwind 4y agoI learnt it a few years before that, and I remember how reading K&R once I got it felt like having someone turn UP the lights, open the blinds, wash the windows and basically TURN UP THE SUN compared to things I read before. So much clarity. Number of times I've seen trigraphs in "real code": still zero. I hope it's the same for you.
- moomin 4y agoI read it at a similar time, and I remember that feeling well. However, if you revisit it with a critical eye, you find a hundred places where a result isn’t checked, bounds aren’t checked, memory is leaked and so on. All of this was pretty much fine in the context in which it was written, but these days bullet-proofing things is pretty much mandatory and K&R’s elegance disappears in the face of such challenges.
- unwind 4y agoWell yeah, but there is a difference between teaching the mechanics of a language, and teaching how to write safe, correct and secure code in that language. Perhaps that mindset is part of what made C survive for so long and in such diverse roles.
- dijonman2 4y agoFantastic book. I used Learn C in 21 days and that is what started everything for me. I had a second book on Linux administration and installed Slackware from 1.44mb disks, ultimately setting up pppd and using Mosaic. Great memories!
- usr1106 4y agoIn 1990 IBM donated a 9370 computer to our university. The default code page for German EBCDIC did not support square brackets. I don't remember whether trigraphs were not supported by the compiler at the time or whether we just wanted to avoid completely unreadable code. Not experienced in VM/370 administration we spent weeks to modify the system to use some international EBCDIC codepage. The system never saw much use, everybody preferred Unix workstations where programming in C was a natural thing.