Xiaoshen Li wrote:
The code is from the book "Practical C Programming" 1997, Chapter 13,
which is available in the link:
http://www.oreilly.com/catalog/pcp3/...h13.html#48674
Example 13-6.
I really like this book. Hard to believe that the author could be wrong.
I don't. I know of enough bad technical books to find it very easy to
believe an author is wrong. In this case though, I believe it is more a
case fo using a very bad style than something that is completely wrong.
I also note that this author is using the term "procedure" when in C it
is usual to refer even to void functions as functions.
It also says, "Finally, there is a special pointer called NULL. It
points to nothing. (The actual numeric value is 0.) The standard include
file, locale.h, defines the constant NULL. (This file is usually not
directly included, but is usually brought in by the include files
stdio.h or stdlib.h.)" which is wrong or misleading on several points.
It is incorrect in saying that NULL is the name of a pointer, NULL is a
macro that expands to a null pointer.
It is correct that locale.h defines the NULL macro.
It is at least misleading saying that that stdio.h and stdlib.h include
locale.h, since on many systems it may not and even if it does you still
won't get the other things that locale.h defines.
It shows an example that modifies a string literal with a comment that
it is legal. This is wrong, the compiler is not required to complain,
but it is also not required to produce working code since attempting to
modify a string literal is undefined behaviour.
It shows using the %p format specifier without casting the pointer to
void*, %p is only valid for pointers to void.
There are probably other errors that I have not spotted on a quick look.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.