In article <42*********************@reader10.nntp.hccnet.nl >,
Erik Leunissen <lo**@the.footer.invalid> wrote:
#if VERSION > "2.3"
..../* conditionally compiled code */
#endif
There is no simple, direct way to do this with macros.
Some unpleasant but workable solutions are:
- Rewrite the macro as separate integers. Then your conditional
compilation can do stuff like:
#if MAJOR_VERSION > 2 || (MAJOR_VERSION == 2 && MINOR_VERSION > 3) /*etc*/
- Rewrite the macro as a single integer with an implied decimal
point, i.e. if you think you'll never have a version between
2.99 and 3.00, you can do this:
#define VERSION 203
and then integer comparisons like
#if VERSION > 203
will do the right thing.
- Use an additional make dependency or a "pre-build" step to run a
small command line program that does something along the lines of:
int major, minor;
sscanf(VERSION, "%d.%d", &major, &minor); /* not the best way */
printf("#define MAJOR_VERSION %d\n", major);
printf("#define MINOR_VERSION %d\n", minor);
printf("#define IMPLIED_DECIMAL_VERSION %d\n", major*100+minor);
with output redirected to a .h file. Then you can use one of
the previous solutions w/o changing VERSION itself.
- If the difference between versions is something like a significant
API change, it's often the case that the API has some new macros or
has removed some old ones. If you can make the conditional
compliation depend on the presense/absence of a guaranteed part of
the API then you don't need to specifically use the version number
itself.
- If the conditionally compiled code is not a huge amount, make it not
be conditionally compiled--do the check for version number at
run time. Convert to double and plain old if's will work. Unless
you have some hard space or time performance limits, it's likely
that the extra overhead will be unnoticeable. Also, this opens up
the possibility of using something like an environment variable
to switch between old and new behaviors.
--
7842++