macro include question

S

sinbad

Hi,
there is a source file "common.c" which will get linked with different
modules.
the code in common.c will look like this.

common.c
--------

#ifdef FEAT_ENABLE
/* function_set_1*/
#else
/* function_set_2*/
#endif

there are two different independent modules(1.c, 2.c) each with it's
own main()
function. Now i want 'function_set_1' for 1.c and 'function_set_2" for
2.c.
So i need to define FEAT_ENABLE for 1.c and must not define
FEAT_ENABLE for 2.c;
The question here is how do i do this without adding any module
specific headers
in common.c;

Any module specific header with "#define FEAT_ENABLE" will get
reflected for other
modules and function_set_2 will get included instead of
function_set_1;
 
S

sinbad

Hi,
there is a source file "common.c" which will get linked with different
modules.
the code in common.c will look like this.

common.c
--------

#ifdef FEAT_ENABLE
/* function_set_1*/
#else
/* function_set_2*/
#endif

there are two different independent modules(1.c, 2.c) each with it's
own main()
function. Now i want 'function_set_1' for 1.c and 'function_set_2" for
2.c.
So i need to define FEAT_ENABLE for 1.c and must not define
FEAT_ENABLE for 2.c;
The question here is how do i do this without adding any module
specific headers
in common.c;

Any module specific header with "#define FEAT_ENABLE" will get
reflected for other
modules and function_set_2 will get included instead of
function_set_1;

any thoughts ?
 
I

Ike Naar

Hi,
there is a source file "common.c" which will get linked with different
modules.
the code in common.c will look like this.

common.c
--------

#ifdef FEAT_ENABLE
/* function_set_1*/
#else
/* function_set_2*/
#endif

there are two different independent modules(1.c, 2.c) each with it's
own main()
function. Now i want 'function_set_1' for 1.c and 'function_set_2" for
2.c.
So i need to define FEAT_ENABLE for 1.c and must not define
FEAT_ENABLE for 2.c;
The question here is how do i do this without adding any module
specific headers
in common.c;

Any module specific header with "#define FEAT_ENABLE" will get
reflected for other
modules and function_set_2 will get included instead of
function_set_1;

Many compilers let you define preprocessor macros on the command line,
e.g. with gcc you can do

gcc -DFEAT_ENABLE 1.c
gcc -UFEAT_ENABLE 2.c

and FEAT_ENABLE will be defined in the 1.c compilation, and
undefined in the 2.c compilation.
 

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

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top