Practical C++ Programming, 2nd Edition by Steve Oualline The unconfirmed error reports are from readers. They have not yet been approved or disproved by the author or editor and represent solely the opinion of the reader. Here's a key to the markup: [page-number]: serious technical mistake {page-number}: minor technical mistake : important language/formatting problem (page-number): language change or minor formatting problem ?page-number?: reader question or request for clarification This page was updated July 27, 2007. UNCONFIRMED errors and comments from readers: [50] bottom; In discussing the substr() function the book states that string.substr(first, last) returns a string containing "all of the characters from /first/ to /last/." In fact, the substr() function is string.substr(first, length) and returns a string starting at position /first/ with length /length/. [62] 3rd paragrah; A more reliable way of doing the same thing is to use the sizeof operator: std::strncpy(name, "Oualline", sizeof(name) - 1); should be: A more reliable way of doing the same thing is to use the sizeof operator: std::strncpy(name, "Oualline", (sizeof(name) / sizeof(name[0])) - 1); This is because we want to obtain the number of characters that we can store in the array, not the number of bytes minus 1. (73) Penultimate sentence. Reference to 'Chapter 1' should be 'Chapter 10'? {83/84} In the example program, the loop would either never execute or loop infinitely because none of the variables the test expression is based on, are changed in the body of the loop. Is this intentional? (85) Exercise 6-3; Doesn't entirely fit in any category, but it would be helpful if the value of a quarter, a dime, a nickel & a penny were listed (particularly a dime & a nickel) -- we're not all used to using US currency day-to-day and don't necessarily know what the names mean. (103) last paragraph; Presumably supposed to be Exercise 7-6, but not titled or typeset as such. Also on this page: Exercise 7-1, Although 'English units' may make sense to someone who uses them every day, the term doesn't make sense to anyone else - Could it be a clumsy way of saying 'Imperial units' or a totally bizarre way of saying 'American units'? (an imperial gallon is different to an American one). The conversion factors, at least for the two example conversions, should be listed. Miles & kilometers are given earlier in the book, but not litres & gallons. Exercise 7-2 is just asking to cause trans-atlantic confusion Exercise 7-3, can a serial transmission line transmit 960 characters (at 8 bits per character) or 960 bits per second? Since bytes seem to be the unit of choice later on, may I suggest that 'characters' becomes 'bytes' (if that's what it's supposed to mean). None of these things should make very much difference, but if someone is using the book to teach from (as seems to be expected with group questions) then having ambiguous questions isn't a good idea. (119) Figure 9-2 Closing brace inside shaded area should be '}' not '{'. Also the shaded area should either include both enclosing braces or neither. As it stands it only contains the closing brace. [129] definition of function "int square(...)"; I have the [02/07] printing. On Page 129, the input parameter to the function is declared as const. Seems to me that this is an error, but as I'm just learning C++, it's possible I'm mistaken. Regards, Philip int square(const int 1) { return (i * i); ) Should be int square(int i) { return (i * i); ) {140} The Recursive "sum" function; /*else*/ return (array[first] + sum(first + 1, last, array)); the sum function should have array_size as follows return (array[first] + sum(first + 1, last, array, array_size)); (141) Half-way down Reference to 'Chapter 1' should be 'Chapter 7'? (142) Top paragraph Reference to 'Chapter 1' should be 'Chapter 7'? (166) Table 11-7 The trailing '2' subscript used for the binary numbers should be smaller. The font is confusing as at first sight it appears that the '2' is the last digit of each binary number. (167-168) Table 11-11 The trailing '2' subscript used for the binary numbers should be smaller. The font is confusing as at first sight it appears that the '2' is the last digit of each binary number. {170-171} Answer 11-1 After presenting a function that turns on pixel (4,7), the text on p.170 suggests generalising this to create a function that turns on a pixel at (x,y). The 'Answer 11-1' on p.170 shows a function that has been generalised to turn on any pixel on the row (x,4) ! (187) Paragraph 4 Reference to 'Chapter 1' should be 'Chapter 11'. (192) stack_push function The 'assert' expression contains a '<=' operator when it should be '<'. It is printed correctly when the function re-appears in the full listing on p.194. (193) stack_pop function The 'assert' expression contains a '<=' operator when it should be '<'. It is printed correctly when the function re-appears in the full listing on p.194. (203) Paragraph 2 Reference to 'Chapter 1' should be 'Chapter 9'. {209} the very first line; struct data { public data { ..... ..... }; }; should be struct data { CLASS data { ..... ..... }; }; {209} top of page; line 1: public data { should be class data { (222) Code snippet at bottom Don't think that the comment for 'int *thing_ptr' should say '(see Figure 15-2B)'. Figure 15-2A is the best figure that describes both this decla- ration and the one for 'int thing'. (223) Code snippet under '&thing' heading. Comment for '*thing_ptr = 5' should probably say '(See Figure 15-2C)' although this still is not ideal because the figure shows '*thing_ptr = 6'. [228] Example 15-2: line before "Another trick to go back to decimal" code comment; Line finishes in a comma ",", but should be semi-colon ";": static_cast(array[index]) << '\n', should be: static_cast(array[index]) << '\n'; (234) Pointers and Structures Reference to 'Chapter 1' should be 'Chapter 12'. {245} Paragraph after coding example; The sentence "For example, -odata.out will work, but -o data.out will not." has an unfortunate line break after the -o in the first -odata.out. This makes both of them look like "-o data.out." That is really contrary to the point the author was trying to get across! {246} code segment; '#include ' needs to be included at the beginning of the code for example 16-1 {250} Line 4 of log_message(...) function in Example 16-2; Should "if (out_file.bad())" be "if (out_file.fail())" ??? {254} 3rd paragraph, last sentence; This is done by the >> operator. should be: This is done by the << operator. {263} Bottom paragraph 'list' in hex is 0x6C697374 Consequently when 0x80808080 is added it becomes 0xECE9F3F4 (266) Bottom line In parenthesis '(the pstd::printf family)' should read '(the std::printf family)' (271) Why 1? Box Second paragraph: Reference to 'parameter #4' should be 'parameter #3'. Third paragraph: First sentence starts 'Since every almost every other standard C...'. Should obviously be 'Since almost every ...' (287) First sentence Line numbers are all wrong. Should say: 'At line 31 the data was good, but when we reached line 32, the data was bad, so the error is located at line 31 ...' (291 and 293-296) Interactive gdb session suggests repeatedly using 'step'. 'next' would probably be a better suggestion (as used previously on p286) because gdb starts diving into the stdc++ library. (306) Code example at bottom An extra 'for (i = 0; i < 10; ++i)' has been printed at the end of the code. (313) 3rd paragraph); "... and add a fudge factor ..." Factor is a dazzling term here. A factor is part of a multiplication, but here it is used for an addition. So a better name would be "fudge summand". {317} Unary Operators The code snippet for a unary '-' actually shows a binary subtraction. Should be inline fixed_pt operator - (const fixed_pt& oper1) { return fixed_pt(-oper1.value); } {319} Postfix code ~1/3rd of way down page; In the postfix incrementing code, 'oper' should be passed by reference instead of by value: inline fixed_pt operator ++(fixed_pt oper,int) should be: inline fixed_pt operator ++(fixed_pt& oper,int) {313 and 327} General comment about the fudge factor. The idea of a fudge factor is explained on p313 and in the code listing on p327 it has been assigned a value of 0.0001. To round a float to the nearest int you just need to add 0.5 before casting it. This is a per- fectly legitimate operation and does not need to be called a 'fudge' or given an arbitrary value such as 0.0001. As it stands the fixed point class would store 9.997 as 999 and then interpret it as 9.99. A 'fudge' of 0.5 would round it correctly to 10.00. {339} Steps 3,4,5 In step 3. The result +1.320E+0 has lost its guard digit. Should be +1.3200E+0. In step 4. The result +1.32000E+0 has now got two guard digits. Should be +1.3200E+0. In step 5. The result +1.3200E+0 has now got one guard digit again! Should be +1.320E+0. {349} 'person' is defined as a class in the code example. A few lines lower it is used as a struct {354 and 369} linked_list::find function a) The line while ((current_ptr->data != name != 0) && should presumably be while ((current_ptr->data != name) && b) The line is also reprinted wrongly on p369 in Answer 20-1. This time 'name' has been changed to 'value' c) The text in the second paragraph says we had to use '(*current_ptr).data' in the code and then introduces the -> operator. Should the code really have been .. while ((*current_ptr).data != name) && ..? Or does the text need rewording ? {355} linked_list::enter function Assuming we are dealing with an *increasing* ordered linked list as all the figures suggest then the following code is wrong. // Did we find the place ? if (item >= after_ptr->data) break; It should be either '(item <= after_ptr->data)' or (item >= before_ptr->data)' {358} double_list::enter function Similar error as above. The code 'if (item >= insert_ptr->data)' should be using '<='. (359) > insert_ptr->previous_ptr->next_ptr = new_ptr >You can see this operation represented graphically in Figure 20-9 This should refer to 'Figure 20-10' > insert_ptr->previous_ptr = new_ptr >This operation is represented graphically by Figure 20-10. This should refer to 'Figure 20-11; {398} middle and bottom; if ((count < 0) && should be if ((count < 0) || (419) 2nd paragraph, 3rd sentence; hard fighting involving tanks, motors, and heavy artillery would make more sense as: hard fighting involving tanks, mortars, and heavy artillery