K & R The C Programming Language 2ed.
The function atof must be declared and defined consistently. If atof itself and the call to it in main have inconsistent types in the same source file, the error will be detected by the compiler. But if (as is more likely) atof were compiled separately, the mismatch would not be detected (p.63)
Actually both gcc and clang can detect the mismatch across files. (Tested on gcc 4.8.2 and clang 3.4.)
the arguments to scanf and sscanf must be pointers. By far the most common error is writing scanf("%d", n); instead of scanf("%d", &n); This error is not generally detected at compile time. (p. 130)
Nowadays both gcc and clang will warn against this.
fabs(x) absolute value of x (p.136)
Actually absolute value of float x, thus the name. C99 adds abs
for int
.
dirwalk
void dirwalk(char *dir, void (*fcn)(char *)) (p.147) (*fcn)(name); (p.148)
Both (*fcn)
can be replaced with fcn
. This alternative syntax is added by C89 standard. So this code is probably from K&R's first edition and did not
get updated.
sbrk returns -1 if there was no space, even though NULL could have been a better design. (p. 152)
Currently on Linux it returns (void *) -1
.
0BSD