Standard scheme for maintainer-only debugging code?

Geert Bosch bosch@gnat.com
Tue Jun 10 19:09:00 GMT 2003


On Tuesday, Jun 10, 2003, at 00:18 America/New_York, Nathanael Nerode 
wrote:

> I can imagine better ways of defining it.  The point is that having one
> guard for such things would be a Good Thing.  Anyone else agree?

I definitely agree with the principle. All #if 0 code and commented-out
should be removed from the compiler. If you want to leave a hint of
how things used to be, you can provide the reference in a comment.
However, I'm not sure using a macro as you suggest is ideal. Their use
is especially troublesome for debugging code: this code tends to bit-rot
as it's not active by default. Humans are good at ignoring the debugging
macros after a while, and so are debuggers. The day one gets enabled,
either on purpose or by accident, the cause of strange behavior may be
hard to track down.

For debugging code, I'd like to propose using a single header
file that has simple boolean constants of the form debug_XYZ.
Then use "if (debug_XYZ) do_this;" code for these cases.
A maintainer who wants to enable the debugging code can do so by
changing the constant to true, or by making it a variable so
debugging can be enabled/disabled from a debugger.

   -Geert



More information about the Gcc mailing list