Conditional compilation

Discussion in 'C Programming' started by ashu, Feb 20, 2012.

  1. ashu

    ashu Guest

    Hi all, I have a very trivial problem with conditional compilation. I
    have a header file called
    wrapper.h which is like the global header file for my project. In this
    header file I want to define a conditional compilation tag called
    DEBUG. This file wrapper.h includes several other files called demo1.h
    demo2.c etc. as follows.

    /***** wrapper.h****/

    #define DEBUG
    #include demo1.h
    #include demo2.h
    ........

    /*****end of wrapper.h**/

    Now if I try to use the conditional compilation flag DEBUG in any of
    these included files, like demo1.h or demo2.h I get an error and the
    compilation fails.

    /**** demo1.h ***/
    # if defined (DEBUG)
    #define BASE_ADDRESS
    #endif

    /***end of demo1.h***/

    Can someone help me and point to me my mistake ? The compilation error
    is BASE_ADDRESS undeclared and I am using GCC.

    regards

    /***end of demo1.h**/
     
    ashu, Feb 20, 2012
    #1
    1. Advertising

  2. ashu

    Ian Collins Guest

    On 02/21/12 06:57 AM, ashu wrote:
    > Hi all, I have a very trivial problem with conditional compilation. I
    > have a header file called
    > wrapper.h which is like the global header file for my project. In this
    > header file I want to define a conditional compilation tag called
    > DEBUG. This file wrapper.h includes several other files called demo1.h
    > demo2.c etc. as follows.
    >
    > /***** wrapper.h****/
    >
    > #define DEBUG
    > #include demo1.h
    > #include demo2.h
    > ........
    >
    > /*****end of wrapper.h**/
    >
    > Now if I try to use the conditional compilation flag DEBUG in any of
    > these included files, like demo1.h or demo2.h I get an error and the
    > compilation fails.
    >
    > /**** demo1.h ***/
    > # if defined (DEBUG)
    > #define BASE_ADDRESS
    > #endif
    >
    > /***end of demo1.h***/
    >
    > Can someone help me and point to me my mistake ? The compilation error
    > is BASE_ADDRESS undeclared and I am using GCC.
    >
    > regards
    >
    > /***end of demo1.h**/


    Showing the actual error and the code where it occurs would help.

    --
    Ian Collins
     
    Ian Collins, Feb 20, 2012
    #2
    1. Advertising

  3. ashu

    Shao Miller Guest

    On 2/20/2012 12:57, ashu wrote:
    >
    > Now if I try to use the conditional compilation flag DEBUG in any of
    > these included files, like demo1.h or demo2.h I get an error and the
    > compilation fails.
    >
    > /**** demo1.h ***/
    > # if defined (DEBUG)
    > #define BASE_ADDRESS
    > #endif
    >
    > /***end of demo1.h***/
    >
    > Can someone help me and point to me my mistake ? The compilation error
    > is BASE_ADDRESS undeclared and I am using GCC.
    >
    > regards
    >
    > /***end of demo1.h**/
    >


    It looks to me like you are forgetting to provide an alternative and are
    using 'BASE_ADDRESS' somewhere in the code regardless of whether or not
    'DEBUG' is defined.

    #if defined (DEBUG)
    # define BASE_ADDRESS value_when_debugging_is_enabled
    #else
    # define BASE_ADDRESS value_when_debugging_is_disabled
    #endif
     
    Shao Miller, Feb 20, 2012
    #3
  4. ashu

    Eric Sosman Guest

    On 2/20/2012 12:57 PM, ashu wrote:
    > Hi all, I have a very trivial problem with conditional compilation.


    Since you haven't solved it, how do you know it's trivial?

    > /***** wrapper.h****/
    >
    > #define DEBUG
    > #include demo1.h
    > #include demo2.h


    Missing some punctuation here, probably " marks.

    > /*****end of wrapper.h**/
    >
    > Now if I try to use the conditional compilation flag DEBUG in any of
    > these included files, like demo1.h or demo2.h I get an error and the
    > compilation fails.
    >
    > /**** demo1.h ***/
    > # if defined (DEBUG)
    > #define BASE_ADDRESS
    > #endif
    >
    > /***end of demo1.h***/
    >
    > Can someone help me and point to me my mistake ? The compilation error
    > is BASE_ADDRESS undeclared and I am using GCC.


    Please post a short and *complete* example of your problem.
    What you've provided above is (1) insufficient to support a
    diagnosis, and (2) quite clearly not the code the compiler saw.

    Good thing the problem's trivial, right?

    --
    Eric Sosman
    d
     
    Eric Sosman, Feb 20, 2012
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris P
    Replies:
    0
    Views:
    443
    Chris P
    Oct 28, 2003
  2. avishay

    Conditional compilation in VHDL

    avishay, Aug 1, 2005, in forum: VHDL
    Replies:
    4
    Views:
    3,047
    Andy Peters
    Aug 1, 2005
  3. Praveen
    Replies:
    0
    Views:
    365
    Praveen
    Apr 12, 2005
  4. Praveen Ramesh
    Replies:
    2
    Views:
    2,188
    Steven Cheng[MSFT]
    Apr 13, 2005
  5. Alec S.
    Replies:
    10
    Views:
    10,226
    Alec S.
    Apr 16, 2005
Loading...

Share This Page