473,699 Members | 2,666 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Ambiguous errata solutions for K&R2

Although not about C++ only, I think many people here have K&R2, so I
post this message in clc++ too.
In K&R2 errata page
<http://www-db-out.research.be ll-labs.com/cm/cs/cbook/2ediffs.html>
there are some ambiguous errata, for which I propose solutions. Any
comments are welcome.

Ambiguous errata (mentioned first) of "The C Programming Language" 2nd
Edition errata page
(http://www-db-out.research.bell-labs.../2ediffs.html), and
proposed solutions that should be added to the errata page exactly as
they appear:
1. "119-121(§5.11): The qsort discussion needs recasting in several ways.
First, qsort is a standard routine in ANSI/ISO C, so the rendition here
should be given a different name, especially because the arguments to
standard qsort are a bit different: the standard accepts a base pointer
and a count, while this example uses a base pointer and two offsets".
Proposed solution:

Rename the "qsort" references, declarations and definitions as "sort" in
the entire section 5.11.

2. "Also, the comparison-routine argument is not treated well. The call
shown on p 119, with an argument

(int (*)(void*,void* ))(numeric? numcmp : strcmp)

is not only complicated, but only barely passes muster. Both numcmp and
strcmp take char * arguments, but this expression casts pointers to
these functions to a function pointer that takes void * arguments. The
standard does say that void * and char * have the same representation,
so the example will almost certainly work in practice, and is at least
defensible under the standard. There are too many lessons in these pages".
Proposed solution:

At the bottom of the page 119 (section 5.11), a note should be added:

"Note: In main(), the call with an argument (int
(*)(void*,void* ))(numeric? numcmp : strcmp) is not only complicated, but
only barely passes muster. Both numcmp and strcmp take char * arguments,
but this expression casts pointers to these functions to a function
pointer that takes void * arguments. The standard does say that void *
and char * have the same representation, so the example will almost
certainly work in practice, and is at least defensible under the standard".

3. "195(§A4.1) The first few sentences might be reworded a bit to
emphasize that there is a distinction between storage duration and
scope, though both are influenced by explicit and implicit storage-class
specifiers".
Proposed solution:

Right after the sentence of A4.1, "Several keywords, together with the
context of an object's declaration, specify its storage class", the
following sentence should be added:

"There is a distinction between storage duration and scope, though both
are influenced by explicit and implicit storage-class specifiers".

4. "245(§B1.3, and also at p. 157 §7.4): The scanf functions do not
ignore white space in formats; if white space occurs at a place in the
format, any white space in the corresponding input is skipped".
Proposed solutions:

On page 157 (7.4) and on page 245 (B1.3), the first sentence with a *
(dot), should be replaced with the sentence:

"* If white space occurs at a place in the format, any white space in
the corresponding input is skipped".

5. "210(§A8.1) : It is said that a register object cannot have the &
operator applied `explicitly or implicitly,' which is true, but needs an
amplifying clause to show that the implicit & comes from mention of an
array name, so declaring an array as a register is fruitless".
Proposed solution:

On page 210 (A8.1), after the sentence "However, if an object is
declared register, the unary & operator may not be applied to it,
explicitly or implicitly", the following sentence should be added:

"The implicit & comes from mention of an array name, so declaring an
array as a register is fruitless".

6. "There is no mention of the offsetof macro in B".

"Index: stddef.h is listed but not summarized in the text; It needs a
section in Appendix B".
Proposed solutions:

At the end of Appendix B, (page 258) the following should be added:

"B12. Common standard type definitions: <stddef.h>

The header <stddef.hdefine s the following types and macros:

The types are:

ptrdiff_t
A signed integral type of the result of subtracting two pointers.

wchar_t
An integral type whose range of values can represent distinct
wide-character codes for all members of the largest extended character
set specified among the supported locales; the null character has the
code value 0 and each member of the basic character set has a code value
equal to its value when used as the lone character in an integer
character constant.

size_t
An unsigned integral type of the result of the sizeof operator.
The macros are:

NULL
NULL expands to an implementation-defined null pointer constant.

offsetof(type, member-designator)
offsetof expands to an integral constant expression of type size_t,
the value of which is the offset in bytes to the structure member
(member-designator), from the beginning of its structure (type)".
Also a reference to offsetof should be added in the INDEX section (page
268).
Jun 27 '08 #1
0 1812

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
7977
by: David | last post by:
this phrase has been mentioned many times in this NG and it seems like everyone know what it's. is it a book? a standard? or a guide of some sort? where can i read more about K&R2? thanks!
12
2167
by: Chris Readle | last post by:
Ok, I've just recently finished a beginning C class and now I'm working through K&R2 (alongside the C99 standard) to *really* learn C. So anyway, I'm working on an exercise in chapter one which give me strange behavior. Here is the code I've written: /****************************************************************************** * K&R2 Exercise 1-9 * Write a program to copy its input to its output, replacing strings of blanks * with a...
16
1676
by: TTroy | last post by:
I FOUND MAJOR ERRORS in K&R2 (making it almost useless for the herein mentioned topics). K&R2 Section 5.9 Pointers vs. Multidimension Arrays starts of like this... "Newcomers to C are somtimes confused about the difference between a two-dimensional array and an array of pointers..." then continues to explain int *b; to be...
3
1922
by: Sunny | last post by:
Hi, Well this might look like a dumb question to 99.99% of u but what exactly is K&R2 and where can I get it? Secondly alot of people say that you can learn by reading good books on C. I know the one by Dennis Ritchie is good but can any one mention some other books as well Thanx.
2
2289
by: arnuld | last post by:
there is a solution on "clc-wiki" for exercise 1.17 of K&R2: http://clc-wiki.net/wiki/K%26R2_solutions:Chapter_1:Exercise_17 i see this uses pointers whereas K&R2 have not discussed pointers yet. i have created a solution myself by modifying the example programme of section 1.19. i tried to find the source-code of K&R2 using Google. i found the home
19
2398
by: arnuld | last post by:
this programme runs without any error but it does not do what i want it to do: ------------- PROGRAMME -------------- /* K&R2, section 1.6 Arrays; Exercise 1-13. STATEMENT: Write a program to print a histogram of the lengths of words in its input. It is easy to draw the histogram with the bars horizontal; a vertical
24
1798
by: Anthony Irwin | last post by:
Hi all, I have been going through the k&r2 book and all the examples are done with main() instead of int main(void) and k&r2 in the start of chapter 1 does not return 0 so I haven't yet either. I did two compiles shown below. $ gcc -std=c89 -Wall exercise_1-9.c -o exercise_1-9 exercise_1-9.c:5: warning: return type defaults to `int'
15
1812
by: arnuld | last post by:
STATEMENT: Write the function strindex(s, t), which returns the position of the rightmost occurence of t in s, or -1 if there is none. PURPOSE: this program prints the index of the rightmost match on the line. The match we have to find is a char array named pattern. We also print out the number of matches we have found. We will take the input from command-line. PROBLEM: Segmentation Fault
7
185
by: Ioannis Vranos | last post by:
In K&R2 errata page <http://www-db-out.research.bell-labs.com/cm/cs/cbook/2ediffs.html> there are some ambiguous errata, for which I propose solutions. Any comments are welcome. Ambiguous errata (mentioned first) of "The C Programming Language" 2nd Edition errata page (http://www-db-out.research.bell-labs.com/cm/cs/cbook/2ediffs.html), and
0
8691
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9180
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9038
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8920
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8887
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7755
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5877
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3060
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2012
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.