In article <60********************************@4ax.com>, Jack Klein <ja*******@spamcop.net> writes:
Neither. What I actually use when I need it, macro names changed from
the actual ones in my source to yours, is:
#undef VERSION_OK
#ifdef VERSION1
#ifdef VERSION2
#error Both VERSION1 and VERSION2 defined
#else
#define VERSION_OK
#endif
#endif
#ifndef VERSION_OK
#error Version Not Specified!
#endif
This catches the error of not defining either version type as early as
possible, before you run into potentially cryptic errors about
undefined symbols later on.
I like the robustness of this version, but I find using the defined()
operator better suited to my tastes:
#if defined(VERSION1) && defined(VERSION2)
#error "Both VERSION1 and VERSION2 defined"
#elif defined(VERSION1)
#include "version1.h"
#elif defined(VERSION2)
#include "version2.h"
#else
#error "Version not specified"
#endif
(I've quoted the argument to the #error directives because some
characters can't appear "bare" in one - the argument to #error has to
be a set of pp-tokens, so for example English contractions are illegal,
because they contain an unescaped single-quote character. I find it
easiest to just always use a quoted string with #error - and not use
double-quote characters within it, of course.)
I find that version more readable than Jack's, and it avoids using
the additional VERSION_OK macro, but this is really just a matter
of personal style.
--
Michael Wojcik
mi************@microfocus.com
How can I sing with love in my bosom?
Unclean, immature and unseasonable salmon. -- Basil Bunting