Project Home
Project Home
Source Code
Source Code
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - Native gcc/qcc preprocessor debug directive?: (4 Items)
   
Native gcc/qcc preprocessor debug directive?  
Hey All - 

Before I go off and create my own, I was wondering if there was a native gcc/qcc preprocessor directive to tell me if 
I'm building a debug version of code...

So it'd be something like this:

#if __DEBUG__
// Do something debug-ish
#else
// Actual production/release stuff
#endif

I know something like this was used previously to control how ASSERT() and TRACE() behaved on Win32 platforms, so I 
figured I'd see if there was something similar in qcc/gcc...

Thanks!

Mike
Re: Native gcc/qcc preprocessor debug directive?  
There is, but the sense is inverted.  NDEBUG is defined if you're building release, and not defined when building debug 
code.

If you want to verify what pre-macros are being used by the compiler, try adding "-g3" to the compiler options.  The 
result is that all macro definitions are output into the object file.  You have to wade through the result with a binary
 editor, but it's a more foolproof way to figure out what definitions exist.  (Note that if you try to use this option 
from the IDE, for the debugging build the IDE will insert the -g after your -g3 and override it.)
Re: Native gcc/qcc preprocessor debug directive?  
Andy Gryc wrote:
> There is, but the sense is inverted.  NDEBUG is defined if you're building release, and not defined when building 
debug code.

NDEBUG gets added by the recursive makefiles as a command line option to 
the compiler driver. gcc does not provide any built-in defines when 
compiling with or without debugging.  The reason gcc does not provide 
any builtin defines is that it should generate the same code when 
debugging is enabled.

Regards,

Ryan Mansfield
Re: Native gcc/qcc preprocessor debug directive?  
A handy way to dump all pre-defined pre-processor macros using a
reasonably modern gcc is:

  gcc -E -Wp,-dM -xc /dev/null | sort -u

(I don't think 2.95.3 supports -dM, but my memory is dreadful so I may
well be wrong.)

Add whatever other compile flags you normally use to see what, if any,
effect they have on the pre-defined pre-processor macros.  The qcc front
end defines a few macros of its own; you can just substitute qcc for gcc
above.

Ryan is correct that gcc doesn't provide a pre-processor macro for -g.
It does, however, provide one for -O (#define __OPTIMIZE__) which you
might be able to use depending on you situation (e.g. if you always do
your debug builds with -O0).

Regards,
Neil

On Fri, 2008-09-05 at 10:41 -0400, Ryan Mansfield wrote:
> Andy Gryc wrote:
> > There is, but the sense is inverted.  NDEBUG is defined if you're building release, and not defined when building 
debug code.
> 
> NDEBUG gets added by the recursive makefiles as a command line option to 
> the compiler driver. gcc does not provide any built-in defines when 
> compiling with or without debugging.  The reason gcc does not provide 
> any builtin defines is that it should generate the same code when 
> debugging is enabled.
> 
> Regards,
> 
> Ryan Mansfield
> 
> _______________________________________________
> General
> http://community.qnx.com/sf/go/post12930
>