Errata for C & C++ Code Capsules


Page xviii:

Line 11: I forgot to mention Jim Thomas as a member of the C Language Support Committee. Sorry Jim!
Line -1: change "Novemver" to "November"

Page 41:

The diagram showing the addresses for j and i have the addresses reversed. j should be at 12FF84 and i should be at 12FF88.

Page 68:

The program near the bottom of the page is sloppy in the declaration of the function f(). It should be as follows:

 
int main()
{
    int (*fp)(const char*, ...) = printf;
    fp("hello, world\n");
}

Page 70:

Near middle of page, the cast for ps2 is missing a const qualifier; it should read

 
* (const char**) p2;

Page 86:

Line 13: change endif to #endif

Page 96:

Line 5: There needs to be a space between the colons in *argv<: :>.

Page 104:

Line -1: Change "Chapter 19" to "Chapter 18".

Page 108:

The following two lines from the middle of the page should be removed:

 
    size_t tlines
    ...
    lines = tlines;

and change assert(tlines); to assert(lines);

Page 116:

The comment in Listing 4.12 should refer to Table 4.8, not Table 4.7.

Page 144:

Line 11: change count-- to --count.

Page 168:

After line 6, insert the following line as the first inside main():

 
using namespace std;

Page 181:

I seem to have forgotten to delete the existing data elements in the assignment operator before cloning the new ones. It should appear as:

 
Person& Person::operator=(const Person& p)
{
    if (this != &p)
    {
        delete [] last;
        delete [] first;
        delete [] ssn;
        last = clone(p.last);
        first = clone(p.first);
        ssn = clone(p.ssn);
    }
    return *this;
}

Since these same delete statements also appear in the destructor, it might be a good idea to define a separate private function (complementary to clone()) to be called in both places instead of replicating code.

Page 182:

Line -10: Change "the user" to "client code".

Page 184:

            In the summary, change “qualifers” to “qualifiers”.

Page 211 - 213:

All occurrences of the data member _Block or Block should read Block_ throughout Listing 9.6.

Page 215:

In Listing 9.8, the statement

 
typedef struct bits Bits;

should read

 
typedef struct Bits Bits;

Likewise near the top of Page 216.

Page 216:

In Listing 9.9, change the structure tag from bits to Bits.

Page 230:

Line 10: Add "for c3" at the end of the first sentence (the one that ends with "44").

Page 270:

Last line: Change "the usual diagnostic" to "a diagnostic only if the name is used".

Page 273:

In Listing 11.10, move the declaration of i inside the for loop. Also, remove the void parameter specification in the function count().

Page 334 - 336:

The macros in xcept.h have extraneous token-pasting operators. A better version would be:

 
// xcept.h:      Useful throw macros
#include <stdexcept>
#include <string>
 
// Macro trick to quote a number:
#define str_(x) #x
#define xstr_(x) str_(x)
 
// Macro for convenient exception throwing
// (includes standard message, file, line #)
#define Throw(Type, cod) \
throw Type ## _Exception(Type ## _Exception:: ## cod, \
                         std::string(__FILE__ ":Line " \
                         xstr_(__LINE__)))
 
#define Throw2(Type, cod, txt) \
throw Type ## _Exception(Type ## _Exception:: ## cod, \
                         txt + std::string(":" __FILE__ \
                          ":Line " xstr_(__LINE__)))

Also, this uses <stdexcept> instead of <exception>, because compilers do not have to specify how they pass a string to the exception object, whereas it is well-defined for runtime_error. The other files now become:

 
// pfxxcept.h
#include "xcept.h"       // See chapter text
using std::runtime_error;
using std::string;
 
class PFX_Exception : public runtime_error
{
public:
    PFX_Exception(int cod, const string& msg = "")
        : runtime_error(s_ErrorStrings[cod] + ":" + msg)
    {}
    enum {BAD_OBJ_ID, CONNECT_ERROR, RECORDSET_ERROR,
          REQUERY_ERROR, UPDATE_ERROR, LOCK_ERROR,
          VERSION_ERROR, TRANS_ERROR, READ_ONLY_ERROR,
          INIFILE_ERROR,
          NUM_ERRORS};
 
private:
    static const string s_ErrorStrings[NUM_ERRORS];
};
 
// pfxxcept.cpp
#include "pfxxcept.h"
 
const string PFX_Exception::s_ErrorStrings[NUM_ERRORS] =
{
    "Bad Objid",
    "Connection open failed",
    "Recordset open failed",
    "Recordset requery failed",
    "Recordset update failed",
    "Record lock failed",
    "Object out of date with database",
    "Transaction error",
    "Attempt to Write a ReadOnly object",
    "INI File name missing"
};

Likewise for sfxxcept.h/cpp.

Page 348:

In the body of recordTime() in the Employee class, remove the "d\" inside the assignment.

Page 403:

Line 15 and 17: Change those last two occurrences of end to begin. Ditto on the top of Page 404. This is the most embarassing typo in the book. Sorry.

Page 417:

Actually, this is probably more embarassing. Change "containers" to "iterators" in Line 17!

Page 480:

Line -15: Put using std::string on its own line.

Page 492:

Line -8: Remove the assertion.

Page 533:

Line -4: Remove the const in the declaration of bad_alloc.

Page 540:

After line 5, add

 
using namespace std;

Page 547:

The listing of keywords is missing export, for, and register.

To report an error, please contact:

cda@freshsources.com