home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / cplus / 19789 < prev    next >
Encoding:
Text File  |  1993-01-23  |  8.1 KB  |  331 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!cs.utexas.edu!uwm.edu!linac!att!cbnewsm!stanl
  3. From: stanl@cbnewsm.cb.att.com (stanley.b.lippman)
  4. Subject: errata -- c++ primer
  5. Organization: AT&T
  6. Date: Fri, 22 Jan 1993 22:23:32 GMT
  7. Message-ID: <1993Jan22.222332.9192@cbnewsm.cb.att.com>
  8. Lines: 321
  9.  
  10.  
  11. here an electronic errata list for the
  12. C++ Primer reflected in the 7th printing
  13.  
  14. let me once again thank the many people who 
  15. have taken the time to note erors ( :-) ) 
  16. and send them on to me.
  17.  
  18. And let me once more very humbly apologize  
  19. for my errrors and the consternation they 
  20. may have caused.
  21.  
  22. stan lippman
  23. at&t bell laboratories
  24. sbl\@research.att.com
  25.  
  26. *********************************************************
  27.  
  28. Note:  I will place this (and earlier errata) under the
  29.        directory AW/Primer on 
  30.  
  31.        world.std.com
  32.  
  33.        both the C++ Primer code and errata will then be
  34.        available via anonymous ftp thanks to Addison-Wesley.
  35.  
  36.        ps: in answer to a post, no, there is no answer
  37.        set.  sorry.
  38.  
  39. *********************************************************
  40.  
  41. Chapter 0:  Getting Started
  42.             (on the wrong foot ...
  43.  
  44. page 1:  Last paragraph should read ``Items 1, 2, and 4 ...''
  45.          rather than ``Items 1, 3, and 4 ...''
  46.  
  47. page 1:  Listing should read ``3a.... 3b.... 3c....'' 
  48.      rather than ``2a.... 2b.... 2c....''
  49.  
  50. page 2:  First sentence, again: 3a, 3b, 3c, not 2a, 2b, 2c.
  51.  
  52. -------------------------------------------------------------
  53.  
  54. Chapter 1: Section 2.5: Increment and Decrement Operators
  55.  
  56. page 75: Bottom of the page, Stack::~Stack()
  57.  
  58.          delete [] array;
  59.  
  60.         Note: the importance of using
  61.  
  62.               delete [] pointer
  63.  
  64.        is to insure that when pointer addresses an array of class objects,
  65.        the compiler applies the destructor of that class to each element
  66.        prior to freeing the memory (generally through a direct call of
  67.        `free'.
  68.       
  69.        thus, for non-class type arrays, old c++ers never actually did use
  70.        the [], which back when required an explicit dimension.  old habits
  71.        die hard -- particularly because they __look__ right.
  72.       
  73.        of course, there is no guarantee that
  74.  
  75.         int *pi = new int[ 10 ];
  76.         // ...
  77.         delete pi;
  78.  
  79.        will always be safe across all implementations and so good style
  80.        says that the bracket pair should always be used, particularly 
  81.        since the introduction of templates, where forms such as
  82.       
  83.               T *pi = new T[ 10 ];
  84.               // ...
  85.               delete pi;
  86.  
  87.         would be seriously wrong if T were instantiated with a class type.
  88.  
  89. -------------------------------------------------------------
  90.  
  91. Chapter 3: Section 3.11: Free Store Allocation
  92.  
  93. page 146: more `delete []' emendation:
  94.  
  95.         delete [] oldia;
  96.  
  97. ---------------------------------------------------------------
  98.  
  99. Chapter 4: Section 4.1: Resolving an Overloaded Function Call
  100.  
  101. page 170:  Last paragraph:
  102.  
  103.        ``Matching can be achieved in on of __four__ ways ...
  104.  
  105.        Note: In the first edition of the Primer, I had combined exact
  106.        match and promotion, so there had only been three.  In the
  107.        second edition, breaking out promotions seemed to clarify things
  108.        (some what, anyway :-)
  109.  
  110. ---------------------------------------------------------------------
  111.  
  112. Chapter 5: Section 5.7: Class Member Pointer
  113.  
  114. Note:  Cfront permits
  115.  
  116.         int (X::*pf)() = X::f;
  117.  
  118.        and treats it as the equivalent of
  119.  
  120.             int (*pfi)() = f;
  121.  
  122.        In the ARM, however, all instances of 
  123.        taking the address of a class member function
  124.        use the address-of operator:
  125.  
  126.             int (X::*pf)() = &X::f;
  127.  
  128.        An admittedly quick reading of the ARM didn't
  129.        dislodge me of the notice that the two forms
  130.        of initializing `pf' are equivalent.  A note
  131.        from Bjarne, however, did:
  132.  
  133.        ``Only &X::f yields a pointer to member (see ref man
  134.     under &).  The reason is that in a member function
  135.     of X, X::f means this->X::f, and I didn't want X::f
  136.     to mean one thing in one context and something
  137.     radically different in another.''
  138.  
  139.         I'd like to thank Chris Skelley for pointing this
  140.     out to me.  Again, at least through 3.*, cfront
  141.         accepts both forms and handles them as equivalent.
  142.  
  143. page 251:  ps_Screen = &Screen::width;
  144. page 252:
  145.        int (Screen::*pmf2)() = &Screen::getHeight;
  146.  
  147.        pmf2 = &Screen::getWidth;
  148.  
  149.            typedef Screen& (Screen::*Action)();
  150.  
  151.        Action deFault = &Screen::home;
  152.        Action next = &Screen::forward;
  153.  
  154. page 253:
  155.  
  156.        Action deFault = &Screen::home;
  157.  
  158.        action( Screen&, Action = &Screen::display );
  159.  
  160.        void ff() 
  161.        {
  162.         
  163.         // ...
  164.         action( myScreen, &Screen::bottom );
  165.        }
  166.  
  167. page 254:
  168.  
  169.        int (Screen::*pmfi)() = &Screen::getHeight;
  170.        Screen& (Screen::*pmfS)(Screen&) = &Screen::copy;
  171.  
  172.  
  173. page 255:
  174.  
  175.        Class Screen {
  176.        public:
  177.         Screen &repeat(Action=&Screen::forward,int=1);
  178.         // ...
  179.        };
  180.  
  181.        myScreen.repeat( &Screen::down, 20 );
  182.      
  183.        Action Menu[] = {
  184.         &Screen::home,
  185.         &Screen::forward,
  186.         &Screen::back,
  187.         &Screen::up,
  188.         &Screen::down,
  189.         &Screen::bottom
  190.         };
  191.  
  192. page 257:
  193.  
  194.       // not double (CoOp::*pf)()
  195.       double (*pf)() = &CoOp::getCost;
  196.  
  197. -----------------------------------------------------------------------
  198.  
  199. Chapter 6: Section 6.3: Operator Overloading
  200.  
  201. page 311: bottom example of overloading operator>>
  202.  
  203.     // Note: comment had read:( ostream&, char* );  
  204.     io >> inBuf; // operator>>( istream&, char* );
  205.  
  206. page 319: again in bottom example, in comment
  207.  
  208.     // wd1.name.String::operator=( wd2.name );
  209.  
  210.     Note: comment had read: // wd.name ...
  211.  
  212. ------------------------------------------------------------------------
  213.  
  214. Chapter 7: Section 7.4: Template Class Specialization
  215.  
  216. page 368:  last example: a real bug -- sorry
  217.  
  218.        #include <string.h>  /* had read: <string.h.
  219.  
  220.        typedef char *p_char;
  221.        QueueItem<p_char>::QueueItem( const p_char& )
  222.  
  223.            Note: 
  224.        in the earlier example, the signature had not 
  225.        exactly matched, and the compiler correctly complained:
  226.  
  227.          QueueItem< char* >::QueueItem( char* )    
  228.  
  229.            unfortunately, cfront 3.* barfs on the inline definition
  230.        of the specialized constructor -- but that is a bug -- 
  231.        the corrected example is, well, correct.
  232.  
  233.  
  234. Chapter 7: Section 7.9: A Template Array Class
  235.  
  236. Note:   Tom Cargill pointed this out to me, for which I thank him.
  237.     It comes from brainlessly transcribing code written for an
  238.     integer class -- 
  239.  
  240. Page 382:  the original code for init() was as follows:
  241.  
  242.     template <class Type> void
  243.     Array<Type>::init(const Type *array, int sz)
  244.     {
  245.             ia = new Type[size = sz];
  246.             assert( ia != 0 );
  247.  
  248.             for (int ix = 0; ix < size; ++ix)
  249.                  ia[ix] = (array!=0) ? array[ix] : (Type)0;
  250.     }
  251.  
  252.         for a class type, such as String, this had the unfortunate
  253.     inefficiency of 
  254.         a. applying String() to each element of the array
  255.         b. converting each (String)0 to a temp by String(int)
  256.         c. applying the memberwise copy operator
  257.  
  258.     ugh!!!!!!  
  259.  
  260.         the revised line is:
  261.  
  262.         ia[ ix ] = array[ ix ];
  263.  
  264.         with the default Array ctor of page 381 rewritten from
  265.  
  266.          Array(int sz=ArraySize) { init(0,sz); }
  267.  
  268.     to
  269.  
  270.          Array(int sz=ArraySize) { 
  271.             ia = new Type[ size = sz];
  272.             assert( ia != 0 );
  273.          }
  274.  
  275.     also, on page 382, Array<Type>::grow(),
  276.     the line
  277.  
  278.         for (; i < size; ++i) ia[i] = (Type)0;
  279.  
  280.     has quietly been removed and
  281.  
  282.         delete [] oldia;
  283.  
  284.     replaces
  285.  
  286.         delete oldia;
  287.  
  288. ------------------------------------------------------------------------------
  289.  
  290. Chapter 8: Section 8.3: Base Class Initialization
  291.  
  292. page 404:  the initialization of Bear in Panda's member initialization
  293.            list is missing an argument:
  294.  
  295.         Bear( "Ailuropoda melaoleuca",
  296.               "Panda", 0, PANDA, MIOCENE )
  297.  
  298.            Note: if I ever do a Third Edition, I think I'll put this
  299.        example to rest ...
  300.  
  301. ---------------------------------------------------------------------------------
  302.  
  303. Chapter 10: Object-Oriented Design
  304.  
  305. page 522, in the Templ_Buf::reset_template() psuedo-code example,
  306.           it should read
  307.  
  308.         def = t;
  309.  
  310. -----------------------------------------------------------------------------------
  311.  
  312. Appendix A: Section A.9: Format State:
  313.  
  314. page 565:
  315.  
  316.     last paragraph now reads:
  317.  
  318.     ``By default, a floating point value has a precision value of 6
  319.     (for values between 10 and 99, for example, the decimal point and
  320.     four digits of precision are printed). ...
  321.  
  322.  
  323.  
  324.  
  325.        
  326.  
  327.  
  328.  
  329.              
  330.  
  331.