### Question 16.5

This program runs perfectly on one machine, but I get weird results on another. Stranger still, adding or removing debugging printouts changes the symptoms...

Lots of things could be going wrong; here are a few of the more common things to check:

- uninitialized local variables (see also question 7.1)
- integer overflow, especially on 16-bit machines, especially of an intermediate result when doing things like `a * b / c` (see also question 3.14)
- undefined evaluation order (see questions 3.1 through 3.4)
- omitted declaration of external functions, especially those which return something other than `int` (see questions 1.25 and 14.2)
- dereferenced null pointers (see section 5)
- improper `malloc`/`free` use: assuming `malloc`ed memory contains 0, assuming `free`d storage persists, `free`ing something twice (see also questions 7.20 and 7.19)
- pointer problems in general (see also question 16.8)
- mismatch between `printf` format and arguments, especially trying to print `long int`s using `%d` (see question 12.9)
- trying to `malloc(256 * 256 * sizeof(double))`, especially on machines with limited memory (see also questions 7.16 and 19.23)
- array bounds problems, especially of small, temporary buffers, perhaps used for constructing strings with `sprintf` (see also questions 7.1 and 12.21)
- invalid assumptions about the mapping of `typedef`s, especially `size_t`
- floating point problems (see questions 14.1 and 14.4)
- anything you thought was a clever exploitation of the way you believe code is generated for your specific system

Proper use of function prototypes can catch several of these problems; `lint` would catch several more. See also questions 16.3, 16.4, and 18.4.

Read sequentially: prev next up top

This page by Steve Summit // Copyright 1995 // mail feedback