----- Original Message -----
From: "basha_ram_id" <basha_ram_id@yahoo.com>
To: <UTTARA@yahoogroups.com>
Sent: Monday, April 26, 2004 11:37 AM
Subject: [UTTARA] (query) if defined


> #if defined(XXXX_XXP)
>
> ..............;
>
> #endif
>
> why  we use such a declartion,and in which case we should use those..
> if defined(XXX.XXXXp)

    This is not a declaration, but a preprocessor directive.  Any line in a
source file that begins with the token, #, counts for a preprocessor directive.

>
> waiting for reply
>
> regards
>
> basha
>

    Googling for "define: conditional compilation", excluding the quotes, will
find you this definition of conditional compilation:

        "During the compilation of a program, a portion of the process (code
            block) that is enabled or disabled by a variable or condition
            external to the code block under consideration. For example, a
            certain program might contain a block that is to be compiled only
            if the compilation is performed on a Digital UNIX system."


Consider the following fragment of code:

    #if constant-expression new-line

        /* one or more statements */

    #else

        /* one or more statements */

    #endif

constant-expression:
    *   should be an integer constant expression
    *   should not contain a cast
    *   can not use sizeof operator and reserved keywords

Operation:
    If the constant-expression results in a non-zero value, then the
immediate block of statements is included for compilation.  If an #else
appears after the block, then the code contained within #else and #endif
is excluded.

    If the constatant-expression evaluates to zero, and if an #else appears,
the #else part is included; otherwise, the block is excluded.

Usage of conditional compilation:

    *   You want your code to be compiled by one or more compilers, and
        want to achieve the same result.

        For example, in the following sample, it is required to avoid the
        warning "identifier defined but not used", programatically.  You would
        achieve it so by using the compiler's extension which are nonportable to
        the another.  So, you use conditional compilation like this:

        /* Avoid warning: `ident' defined but not used */
        #ifdef __GNUC__
        #define UNUSED  __attribute__ (( unused ))

        /* Turbo C/C++ specific */
        #elif __TCPLUSPLUS__ && __MSDOS__
        #define UNUSED
        #pragma warn -var

        #else
        #define UNUSED
        #endif

        static int i UNUSED;
        static int j UNUSED = 10;
        int ii UNUSED;

    *   You want your code to be portable across two or more OSes, as
        aforementioned in the definition.

        Generally, all compilers #define macros which identify the operating
        system.  GCC, under Linux, #defines the macros __linux__, unix etc.
        Turbo C/C++ #defines the macro, _Windows.  For example,

            #if defined (__linux__) || defined (unix)

                system ( "clear" ); /* or use curses functionality */

            #elif defined (_Windows) && defined (__TCPLUSPLUS__)

                clrscr ();

            #endif

    *   There are many other usage of these constructs which depends on the
        situations or requirements.  For example, as header guards.

    *   There are other constructs similar; like #ifdef, #ifndef which
        I haven't talked about.