Compile a section of code if an identifier is defined

     #ifdef <identifier>


     <identifier> is the name of a definition whose existence is being


     #ifdef...#endif lets you perform a conditional compilation.  It does
     this by identifying a section of source code to be compiled if the
     specified <identifier> is defined.  The <identifier> can be defined
     using either the #define directive or the /D compiler option which lets
     you define an identifier or manifest constant from the compiler command

     The #else directive specifies the code to compile if <identifier> is
     undefined.  The #endif terminates the conditional compilation block.

     Conditional compilation is particularly useful when maintaining many
     different versions of the same program.  For example, the demo code and
     full system code could be included in the same program file and
     controlled by a single #define statement.


     .  This code fragment is a general skeleton for conditional
        compilation with #ifdef:

        #define DEMO
        . <statements>
        #ifdef DEMO
           <demo specific statements>

     .  This example controls conditional compilation with an
        identifier defined on the compiler command line with the /D option.

        In DOS:

        C>CLIPPER Myfile /DDEBUG

        In the program (.prg) file:

        #ifdef DEBUG
           Assert(<some condition>)

     .  This example defines a manifest constant to one value if it
        does not exist and redefines it to another if it exists:

        #ifdef M_MARGIN
           #undef  M_MARGIN
           #define M_MARGIN   15
           #define M_MARGIN   10

See Also: #define #ifndef

5 responses to “C5_#ifdef

  1. Pingback: C5_#undef | Viva Clipper !

  2. Pingback: C5_#ifndef | Viva Clipper !

  3. Pingback: C5_#error | Viva Clipper !

  4. Pingback: C5_#define | Viva Clipper !

  5. Pingback: C5 Directives | Viva Clipper !

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.