🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c.moderated
Article #2458

Annotations on K&R II

#2458
From: J. Blustein
Date: Tue, 02 Apr 1996 01:55
183 lines
9253 bytes
     This summer, I reread the New Testament and started making notes in
the margin.  I don't normally mark up books, but I thought it worthwhile
this time.  I think that other C programmers, particularly new ones, will
find my list of annotations useful.  I put a copy on the WWW at
http://www.csd.uwo.ca/%7ejamie/.Refs/.Footnotes/C-annotes.html but that
won't be around forever.  This posting is my attempt to get the list out to
a greater audience and perhaps even have it preserved somewhere.


  ANNOTATIONS ON K&R II
  
    Purpose
    
        Upon re-reading The C Programming Language (second edition) by
   Brian W. Kernighan and Dennis M. Ritchie (aka K&R II) I was surprised
   find out how much richer it is than I had remembered.  I took the
   uncharacteristic step of writing notes in the margins of my copy. Some
   of those notes are reproduced below in the hopes that others will find
   them helpful too.
   
        I don't want to give the impression that K&R II should replace the
   ISO Standard or the ANSI Rationale.  I use K&R II as an introduction
   and tutorial to the C language.  Experienced C programmers will find
   Harbison and Steele's C: A Reference Manual a  better reference work
   (in my opinion, of course).  The Standard is, as its title implies, the
   definition of the modern C language.   Harbison and Steele provide
   descriptions of both ISO/ANSI and pre-ANSI C, by the way.
   
  THE ANNOTATIONS
  
        I've listed my annotations in three parts: clarifications,
   cross-references and scattered discussions.  Also, I keep a very short
   list of so-called quick-references below.
   
    Clarifications
    
     p. 6                   main() requires a return (see p. 26)
                         
     p. 9                   comments do not nest (see p. 34)
                         
     p. 90                  ## and # are used during macro expansion only.
                            The comp.lang.c FAQL has something to say about
                            this point, see question 11.17.
                         
     pp. 94, 103, 120       void * cannot hold function pointers.  For
                            further clarification within K&R II see
                            Sections A6.8 (Pointers to Void on p. 199), A.4
                            (Meaning of Identifiers on p. 195) and A.5
                            (Objects and Lvalues on p. 197).
                         
     p. 135                 As the text states: sizeof *x is the size of the
                            pointer not the x being pointed to.
                         
     p. 143                 I think that a user supplied definition of
                            strdup() (which is not in the standard library
                            by the way) would violate the ISO standard for
                            function names.  Steve Summit wrote about this
                            in question 1.29 (pp. 23-26) of C
                            Programming FAQs.
                         
     p. 159                 I find the statement that `an array name is a
                            pointer' misleading. See p. 99 for the details.
                         
     p. 119                 Note that: 1) char * is not the same as void *
                            and 2) this qsort() is not necessarily the same
                            as the standard library's.  (I got these points
                            from a comment on p. 229 (question 13.8) of
                            Steve Summit's C Programming FAQs.)
                         
     p. 163                 Also, in my experience, stderr is unbuffered.
                         
     p. 183                 <sys/types.h> does not define size_t. It is
                            defined in <stddef.h> (pp. 260-1).
                         
     p. 255                 tm_sec: there can be as many as 2 leap seconds
                         
     p. 257                 %S: there can  be as many as 2 leap seconds
                         

         I found the errata notices helpful too.  (See
   http://www.csd.uwo.ca/%7ejamie/.Refs/.Footnotes/K%26RII-errata.html for
   the January 1991, June and July 1992 versions).


    Cross-references
    
       I've included references to expanded definitions that appear later
   in the text.  My copy also has exact page numbers for many of the
   cross-references by section, but there is little point to include those
   here.
   
     p. 26                  The conventional interpretation of the return
                            statement appears at the top of p. 164.
                         
     p. 33                  See extern declarations below
                         
     p. 40                  The definition of static is on p. 83
                         
     p. 40                  variable initialization is dealt with on p. 85
                         
     p. 42                  NULL is zero (see p. 102)
                         
     p. 48 (Section 2.9: Bitwise Operators)
                            see also Section 6.9 (Bit-fields) on 
                            pp. 149-150
                         
     p. 48                  There is an example of operator precedence on
                            p. 52 (Section 2.12)
                         
     p. 63                  A different swap appears on p. 96
                         
     p. 83 (Section 4.7: Register Variables)
                            Even though the compiler is free to ignore the
                            declaration register variables can be used as
                            documentation that the variables will be
                            heavily used and that its address will not be
                            computed, e.g. the & operator will not be
                            applied to them.
                         
     p. 77                  See `extern declarations' (in `Scattered
                            Discussions', below)
                         
     p. 80                  See extern declarations, below
                         
     pp. 91, 103            sizeof is explained on p. 135
                         
     p. 96                  Compare this swap with pp. 62-3 and p. 88
                         
     p. 101                 static variables are defined on p. 83
                         
     p. 57 (Section 5.7 Multi-dimensional Arrays)
                            See also Section A.6.2 (Array Declarators on
                            pp. 216 - 7)
                         
     p. 165                 register declaration introduced on p. 83
                         
     p. 174                 Section 7.6:Error Handling -- Stderr and Exit is
                            on pp. 163-4
                         
     p. 174                 Section 7.3:Variable-length Argument Lists is on
                            pp. 155-6
                         
    Scattered Discussions
    
      extern declarations
        introduced on             p. 33
        example on                p. 77
        additional discussion on  p. 80 (Section 4.4)

    Quick References
    
      Below are some notes I use myself as a mini index.
   
         Array bounds           p. 100
                         
         Arrays are row major (final dimension varies fastest)
                                p. 112
                         
         Boolean values (0 == FALSE)
                                p. 42
                         
         Brace style            p. 10
                         
         printf() string precision examples
                                p.154


    See also
      My list of recommended programming books is at
   http://www.csd.uwo.ca/%7ejamie/.Refs/tech-books.html.  All of the books
   referenced to here are described in greater detail there.  Bibliographic
   references for them are also available from the comp.lang.c FAQ list.

    Document details
      Last updated by J. Blustein on 30 March 1996.  This version created
   with the help of the CERN line-mode browser version 4.0D on 1 April
   1996.

      This document is copyright by its author, J. Blustein <jamie@uwo.ca>.
   The author grants permission for free distribution of this document.
-- 
Jamie Blustein                                         `Did you say "knives"?'
<jamie@uwo.ca>                                         `*Rotating* knives, yes.'
Technical Details
Message-ID: <4jq1eq$a3c@solutions.solon.com>
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
From: jamie@csd.uwo.ca (J. Blustein)
Newsgroups: comp.lang.c.moderated
Subject: Annotations on K&R II
Date: 1 Apr 1996 19:55:37 -0600
Organization: Computer Science Dept., Univ. of Western Ontario, London, Canada
Sender: clc@solutions.solon.com
Approved: clc@solutions.solon.com
Message-ID: <4jq1eq$a3c@solutions.solon.com>
Reply-To: jamie@uwo.ca
NNTP-Posting-Host: solutions.solon.com
X-Copyright: copyright (c) J. Blustein, 1996.  All rights reserved 
X-Url: http://www.csd.uwo.ca/%7ejamie/.Refs/.Footnotes/C-annotes.html