Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   Conditional compilation (http://www.velocityreviews.com/forums/t868556-conditional-compilation.html)

ashu 02-20-2012 05:57 PM

Conditional compilation
 
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**/


Ian Collins 02-20-2012 06:42 PM

Re: Conditional compilation
 
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

Shao Miller 02-20-2012 07:52 PM

Re: Conditional compilation
 
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

Eric Sosman 02-20-2012 07:52 PM

Re: Conditional compilation
 
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
esosman@ieee-dot-org.invalid


All times are GMT. The time now is 10:23 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.