Mail Archives: djgpp/2002/03/24/10:59:57
> From: CBFalconer <cbfalconer AT yahoo DOT com>
> Newsgroups: comp.os.msdos.djgpp
> Date: Sun, 24 Mar 2002 12:38:22 GMT
> >
> > It's IMHO a bad idea to turn off optimizations when debugging a program.
> > Compilers these days do such complicated code changes when optimizing
> > that you are effectively debugging a very different program. So you
> > either need to debug the program twice, first without optimizations, then
> > with them (and who has the will power and resources to do that?), or use
> > untested program when you turn on optimizations for production version.
>
> True enough, but you are usually debugging your own logical errors
> rather than performance issues (or compiler optimizer bugs).
The effect of a bug can be very different with and without
optimizations. For example, uninitialized variables are known to
produce different effects depending on memory or register contents, so
they might well go unnoticed in an unoptimized program, but then raise
their ugly head in the production version.
Functions that are inlined by the compiler are another similar case:
the inlined code is typically less safe than a library function (it
trades safety for speed).
> With me such step by step debugging is a last resort anyhow. A
> mild sprinkling of asserts and printfs is usually much more
> productive.
There are bugs that cannot be practically found with printf debugging.
One example is code that overwrites random locations. You need
something like watchpoints with those bugs.
Also, inserting printf's might disable some optimizations (although
not as much as omitting the optimization switches altogether), and you
again get a different program.
> At any rate I think we are agreed that the OP has been confused by
> the optimization.
Sure.
- Raw text -