Conditional compilation

A

ashu

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**/
 
I

Ian Collins

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.
 
S

Shao Miller

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
 
E

Eric Sosman

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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top