On 27.02.2011 16:18, David Nadlinger wrote:
On 2/27/11 3:52 PM, simendsjo wrote:
I'm having some problems grokking version.

How would I translate this simple C macro?
#if !defined(IDENT) || !defined(IDENT2)

You are facing a quite common question, with the answer being that there
is no simpler way to do this, at least that I know of.

This has to do with both the stage at which version blocks are parsed
internally, and with Walter taking a defensive stance on the power of
version statements because he feels that the typical C preprocessor
constructs are often a source for confusion (sorry if I misquoted you
there).

If you need more complex version conditions, however, you could consider
mapping versions to manifest constants and using static ifs like this:

version (foo) {
enum version_foo = true;
} else {
enum version_foo = false;
}

static if (version_foo || (version_bar && !version_baz) ) {
…
} else {
…
}


David

Thanks. A nice idea, and it makes the code prettier.
I can even use the same identifier names:

version(IDENT)
    enum IDENT = true;
else
    enum IDENT = false;

version(IDENT2)
    enum IDENT2 = true;
else
    enum IDENT2 = false;

static if(IDENT || IDENT2) {
}

Reply via email to