code quality dds

Code QualityFAQ

What is the code appearing on the book's cover?

A list of comments marking code parts of dubious quality. You can read the full list of such comments appearing in the book's CD-ROM here.

What is the answer to exercise N?

If N == 5.8 this is your lucky day: you can find an answer here. Otherwise, read on.
Most exercises are quite open-ended and do not have one correct answer. Besides, the objective of the exercises it to do them on your own.

I think the book contains an error on page [...] .

Please first have a look on the errata page to see if this is a known and documented error. If it isn't, you might have found a new one. Please drop me a line with a short description of the error, the page number, and the book's printing number (shown on the bottom of the fourth page). If this is an error in the text I wrote, I will probably add it in the errata page with a reference to your name (unless you ask for your contribution to remain anonynous). Errors in the open source code examples also interest me, but do not go in the errata page; I might include a note in a subsequent edition.

Can I use the tricks I learn from reading the book's GPLed code at work?

The GNU General Public License is associated with the code's copyright. Copyright protects the expression of an idea, not the idea itsself. Thus, using a variable name appearing in GPLed code one has read could be problematic, but adopting a design used in GPLed code in new code one creates should be ok. In addition, none of the code appearing in the book is GPLed. I have used code licensed under BSD and similar licenses, to avoid problems with intepreting the GPL and its requirements.
Disclaimer: I am not a lawyer, and this is not legal advice.

How could the error function appearing on p. 297 fail? Its parameters simply create a copy of the stack frame.

The error function will fail on an architecture where the size of pointers is larger than the size of integers, when a pointer with a value that can't fit into an integer is passed to it. The value will get truncated to the size of the integer, and the error function will operate on a different pointer.

As an example, the following program will crash on an Alpha processor under FreeBSD 5.5

error(fmt, a, b, c, d, e, f, g)
	char *fmt;
{
        printf(fmt, a, b, c, d, e, f, g);
}

main()
{
	char *s = "world";
        error("Hello %s\n", s);
}
On an AMD-64 with Linux the error is more devious. The program will work as long as the allocated data size is less than 4GB. When pointers exceed that value (as in the following example) the program will crash.
#include <stdlib.h>

error(fmt, a, b, c, d, e, f, g)
	char *fmt;
{
        printf(fmt, a, b, c, d, e, f, g);
}

main()
{
        char *p = malloc(4l * 1024 * 1024 * 1024);
        char *s = malloc(4l * 1024 * 1024 * 1024);
        strcpy(s, "world");
        error("Hello %s\n", s);
}

I don't agree with what you write on p. 477. Shouldn't pow(-1, ∞) return a NaN? I tried it on OpenBSD with gcc and glibc and it does.

The C99 standard in section F.9.4.4 states: pow(-1, ±∞) returns 1. Some older versions of glibc did indeed return NaN, but this error has now been fixed.

My question is not answered here. What now?

See my personal FAQ list, and if that fails to answer your question send me an email with a concise description of your question. Keep in mind that I receive more than a hundred messages every day, so I may take some time to answer to your message.

Book homepage | Author homepage


Valid XHTML 1.0! Level Triple-A conformance icon, W3C-WAI Web Content Accessibility Guidelines 1.0 Creative Commons License Unless otherwise expressly stated, all original material on this page created by Diomidis Spinellis is licensed under a Creative Commons Attribution-Share Alike 3.0 Greece License.
Last modified: 2006-07-24