comp.lang.c FAQ list
·
Question 16.5
Q:
This program runs perfectly on
one machine,
but I get weird results on
another.
Stranger still,
adding or
removing a debugging printout
changes the symptoms...
A:
Lots of things could be going wrong;
here are a few of the more common things to check:
- uninitialized local variables
[footnote]
(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,
or have ``narrow'' or variable arguments
(see questions
1.25,
11.3,
14.2,
and 15.1)
 - dereferenced
null pointers
(see section 5)
 - improper malloc/free use:
assuming malloc'ed memory contains 0,
assuming freed storage persists,
freeing something twice,
corrupting the malloc arena
(see also questions
7.19
and
7.20)
 - pointer problems in general
(see also
questions 16.7 and 16.8)
 - mismatch between
printf format
and arguments,
especially trying to print long ints using %d
(see
questions 12.7 and 12.9)
 - 
trying to
allocate
more memory than an unsigned int can count,
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
[footnote]
(see also
questions 7.1, 12.21, and 19.28)
 - invalid assumptions about the mapping of typedefs,
especially size_t
(see question 7.15)
 - floating point problems
(see questions 14.1 and 14.4a)
 - 
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.
 
about this FAQ list
 
about eskimo
 
search
 
feedback
 
copyright
Hosted by