H
Harold Weissman
I have a C file that contains (among other things) a number of
macros that will be replaced depending on whether or not a compile-time
option is defined. For example, two functions f and g in that file might
be
int f(void)
{
int x ;
x = MY_SYMBOL ;
return x + 3 ;
}
int g(void)
{
int y ;
y = MY_SYMBOL ;
return y + 4 ;
}
We also have, in some include file used by the C file in question,
#ifdef COMPILE_TIME_FLAG
#define MY_SYMBOL 1
#else
#define MY_SYMBOL 0
#endif
What I would like is for x to be assigned 1 or 0, depending on whether or
not COMPILE_TIME_FLAG is defined, while y is to be assigned 0 no matter
whether or not COMPILE_TIME_FLAG is defined. As you can see, this is a
toy example that is trivially solved by other means; I am just
illustrating a general question.
Something I tried was
#define NO_REPLACE
int g(void)
{
int y ;
#ifdef COMPILE_TIME_FLAG
#ifdef NO_REPLACE
#undef COMPILE_TIME_FLAG
#define SET_COMPILE_TIME_FLAG
#endif
y = MY_SYMBOL ;
#ifdef SET_COMPILE_TIME_FLAG
#define COMPILE_TIME_FLAG
#endif
#endif
return y + 4 ;
}
but it does not work (and it is ugly to boot.)
Any ideas as to how to do this? Actually, is it doable?
macros that will be replaced depending on whether or not a compile-time
option is defined. For example, two functions f and g in that file might
be
int f(void)
{
int x ;
x = MY_SYMBOL ;
return x + 3 ;
}
int g(void)
{
int y ;
y = MY_SYMBOL ;
return y + 4 ;
}
We also have, in some include file used by the C file in question,
#ifdef COMPILE_TIME_FLAG
#define MY_SYMBOL 1
#else
#define MY_SYMBOL 0
#endif
What I would like is for x to be assigned 1 or 0, depending on whether or
not COMPILE_TIME_FLAG is defined, while y is to be assigned 0 no matter
whether or not COMPILE_TIME_FLAG is defined. As you can see, this is a
toy example that is trivially solved by other means; I am just
illustrating a general question.
Something I tried was
#define NO_REPLACE
int g(void)
{
int y ;
#ifdef COMPILE_TIME_FLAG
#ifdef NO_REPLACE
#undef COMPILE_TIME_FLAG
#define SET_COMPILE_TIME_FLAG
#endif
y = MY_SYMBOL ;
#ifdef SET_COMPILE_TIME_FLAG
#define COMPILE_TIME_FLAG
#endif
#endif
return y + 4 ;
}
but it does not work (and it is ugly to boot.)
Any ideas as to how to do this? Actually, is it doable?