Test for debug vs release

  • Hi all,

    OK, I'm missing something obvious here.

    How can I test whether my program is running in debug or release? I'd like to wrap a bunch of log file writes in an if statement so it only bothers if I'm debugging?

    How can I detect debug at compile time? (eg #if ISDEBUGGING)

    How can I detect at runtime?

    Thanks,
    Tom
    BareFeet
  • Go to your project Info panel, and make sure the debug configuration is chosen. In the Language section add -DISDEBUGGING to the Other C Flags

    Then you will be able to use #ifdef ISDEBUGGING etc in your code.

    HTH

    Gideon

    On 21/03/2010, at 3:22 PM, BareFeet wrote:

    > Hi all,
    >
    > OK, I'm missing something obvious here.
    >
    > How can I test whether my program is running in debug or release? I'd like to wrap a bunch of log file writes in an if statement so it only bothers if I'm debugging?
    >
    > How can I detect debug at compile time? (eg #if ISDEBUGGING)
    >
    > How can I detect at runtime?
    >
    > Thanks,
    > Tom
    > BareFeet
  • On 2010 Mar 20, at 22:27, Gideon King wrote:

    > Go to your project Info panel, and make sure the debug configuration is chosen. In the Language section add -DISDEBUGGING to the Other C Flags

    Yes; note that the leading -D is part of the syntax.  I believe that DEBUG is somewhat conventional, instead of ISDEBUGGING.

    > On 21/03/2010, at 3:22 PM, BareFeet wrote:

    >> How can I detect at runtime?

    Search list archives for 2 days ago, 2010 03 18, for thread subject "Detecting if you're being debugged".

    Always search list archives :))
  • You can also do:

    #if !defined( NDEBUG )
        /* Debugging Stuff Goes Here *.
    #endif

    I don't have an Xcode install handy to actually check (I'm
    reinstalling my Mac today), but NDEBUG *should* be defined for release
    builds, and not defined for debug builds.

    The reason is that the assert macro in <assert.h> disables itself if
    NDEBUG is defined.  I am under the impression that the presence or
    absence of NDEBUG is specified by the ANSI C definition, but I'm not
    completely certain.

    Don Quixote
    --
    Don Quixote de la Mancha
    <quixote...>
    http://www.dulcineatech.com

      Dulcinea Technologies Corporation: Software of Elegance and Beauty.
  • On Sun, Mar 21, 2010 at 11:01 AM, Don Quixote de la Mancha
    <quixote...> wrote:
    > You can also do:
    >
    > #if !defined( NDEBUG )
    >    /* Debugging Stuff Goes Here *.
    > #endif
    >
    > I don't have an Xcode install handy to actually check (I'm
    > reinstalling my Mac today), but NDEBUG *should* be defined for release
    > builds, and not defined for debug builds.
    >
    > The reason is that the assert macro in <assert.h> disables itself if
    > NDEBUG is defined.  I am under the impression that the presence or
    > absence of NDEBUG is specified by the ANSI C definition, but I'm not
    > completely certain.
    >

    The presence or absence of NDEBUG is not defined by the C standard
    *however* the behaviour of the assert macro, when *you* define NDEBUG,
    *is* specified:

    "If NDEBUG is defined as a macro name at the point in the source file
    where <assert.h> is included, the assert macro is defined simply as
    #define assert(ignore) ((void)0)"

    --
    Clark S. Cox III
    <clarkcox3...>
  • On Mar 21, 2010, at 11:10 AM, Clark Cox wrote:
    > The presence or absence of NDEBUG is not defined by the C standard
    > *however* the behaviour of the assert macro, when *you* define NDEBUG,
    > *is* specified:
    >
    > "If NDEBUG is defined as a macro name at the point in the source file
    > where <assert.h> is included, the assert macro is defined simply as
    > #define assert(ignore) ((void)0)"

    Defining NDEBUG for non-debug builds is traditional, but Xcode doesn't do it by default. If you want to follow tradition, add NDEBUG to the Preprocessor Macros of your Release build.

    --
    Greg Parker    <gparker...>    Runtime Wrangler
previous month march 2010 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today