Conditional compilation

Hej !

I don’t know if it’s a bug or not, this works :

class Test {
    static function main() {
        trace( #if haxe < 4 "Haxe is great!" #else "foo" #end);
    }
}

But this doesn’t :

class Test {
    static function main() {
        trace( #if haxe_ver < 4 "Haxe is great!" #else "foo" #end);
    }
}

Actually, neither of these work. The < 4 condition is not part of the conditional unless you enclose it in parens:

trace(#if (haxe_ver < 4) "Haxe is great!" #else "foo" #end);

The haxe define is meant to be used together with the SemVer comparison syntax that was added in Haxe 4:

trace(#if (haxe < version("4.0.0")) "Haxe is great!" #else "foo" #end);

However, that’s more for “granular” checks (and it won’t have the desired effect either - because the syntax is new, it won’t parse with Haxe 3.x). If you just want to check for Haxe 4, simply use the haxe4 define.

trace(#if !haxe4 "Haxe is great!" #else "foo" #end);

Thanks for explanation !

I’m sorry it’s also my fault, I’ve several error and in fact #if (haxe_ver >= 4) works but I was confused with another error and thought it was this one.
Anyway it’s good to know all this conditions

You can check on #if haxe3, which works for Haxe 3.x
And you check on #if haxe4, which works for Haxe 4.x

Both checks don’t fail on either Haxe 3 or Haxe 4.
I think it is better to use #if haxe3 compared to #if !haxe4 (in case Haxe 5 will be released)

I think if you use the #if (haxe < version("4.0.0")) that will cause compilation errors on Haxe 3 builds, because this syntax was introduced in Haxe 4

haxe4 will still be defined in Haxe 5, just like haxe3 is still defined right now. #if haxe4 should be read as “if Haxe is >= 4”.