On Wed, Jul 22, 2009 at 10:42, John (Eljay) Love-Jensen<eljay@xxxxxxxxx> wrote: > Hi Paulo, > > Since the early days of K&R C and Unix, the define NDEBUG has been used, and is still used by the C <assert.h> header file, and by the C++ <cassert> header file. > > To get the debug behavior, you need to compile like this: > > gcc Foo.c > > To get the release (non-debug) behavior, you need to compile like this: > > gcc -DNDEBUG Foo.c > > To isolate debug-only code blocks, you do this: > > #ifndef NDEBUG > DebugTrace("yada yada"); > #endif > > To isolate release-only code blocks, you do this: > > #ifdef NDEBUG > ReleaseOnly("yada yada"); > #endif > > To create a (say) TRACE macro that is only in your code for debug-only, you could do this: > > #include <iostream> > #ifdef NDEBUG > #define TRACE(x) ((void)0) > #else > #define TRACE(x) std::cerr << x << std::endl > #endif > > The use of _DEBUG is something I've only run across in Microsoft's headers. (It may be used by others as a convention, but I haven't bumped into that yet.) > > You are at liberty to use your own preprocessor symbol to indicate debug-vs-nondebug compilations. DEBUG, _DEBUG, __DEBUG__, __DEBUG or whatever. Be warned, though, that _DEBUG, __DEBUG, __DEBUG__ are all reserved symbols. So you are better off using DEBUG or PFS_DEBUG (for examples). > > I find NDEBUG a little confusing because of the double-negative #ifndef NDEBUG, but that's just me. I'm a bear of small brain. > > HTH, > --Eljay > Thanks Eljay for the quick answer. Your answer help me a lot, specially about the TRACE trick. About the "reserved symbols", I tried to discover it and didn't found anywhere. Is there any command or gcc parameter to know the reserved symbols? The only way that I got is to create a program to print all known defines. Thanks again, Paulo Flabiano Smorigo