DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: #ifdef

  1. #1
    foolguy Guest

    #ifdef


    what is this for

    #define DEBUG
    //...
    #ifdef DEBUG
    //...
    #endif

    can someone give me some example?

  2. #2
    Christopher Thomas McGinlay Guest

    Re: #ifdef

    foolguy wrote:

    > what is this for
    >
    > #define DEBUG
    > //...
    > #ifdef DEBUG
    > //...
    > #endif
    >
    > can someone give me some example?


    Hi,

    It is for conditional compilation - if you are in 'debug mode' (have
    defined DEBUG) then the compiler will compile code between the #ifdef
    and #endif directives. Otherwise the compiler will ignore it (usually
    for compiling in release mode).

    I don't know much about its merits and demerits, perhaps others here can
    comment?

    Chris

    --
    Ascent Software Limited Registered in Scotland: SC201671
    ascent@zetnet.co.uk Bank Of Scotland Buildings
    01950 422 431 Lerwick, Shetland, ZE1 0EB


  3. #3
    Danny Kalev Guest

    Re: #ifdef



    Christopher Thomas McGinlay wrote:
    >
    > foolguy wrote:
    >
    > > what is this for
    > >
    > > #define DEBUG
    > > //...
    > > #ifdef DEBUG
    > > //...
    > > #endif
    > >
    > > can someone give me some example?

    >
    > Hi,
    >
    > It is for conditional compilation - if you are in 'debug mode' (have
    > defined DEBUG) then the compiler will compile code between the #ifdef
    > and #endif directives. Otherwise the compiler will ignore it (usually
    > for compiling in release mode).
    >
    > I don't know much about its merits and demerits, perhaps others here can
    > comment?


    yes, some of use don't use decent debuggers, either because they're too
    expensive and buggy, or because they simply don't exist (this is a
    common scenario in the embedded system realm, for instance) so instead
    of using the debugger's "step" command and see the program's flow of
    execution, one might put a printf() statement in a code block that is
    conditionally compiled -- in the debug version, you will see the output,
    say, "now calling function myfunc...", but not in release mode. If
    you're looking for a more realistic example, consider the assert() macro
    which is based on this very technique.

    Danny
    >
    > Chris
    >
    > --
    > Ascent Software Limited Registered in Scotland: SC201671
    > ascent@zetnet.co.uk Bank Of Scotland Buildings
    > 01950 422 431 Lerwick, Shetland, ZE1 0EB


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center