Does Julia have something like #ifdef in C++ for conditional compile

Is there anything like
#ifndef or #if in C++ to ignore some code according to the constant definition.
I want to ignore some code for the testing purpose.

Try,

@static if @isdefined(var)

Note the condition isn’t limited just to @isdefined, anything that evaluates at parse time should be fine.

8 Likes

Julia does no have the equivalent to c++ preprocessor, which is different from normal branches that the code enclosed does not have to be valid syntax. Julia does have normal branches, which should be used here. If you just wan to disable some debugging code, you shoul just use a normal branch based on a condition that’s a constant. This is also better in c as well since it makes sure your debugging code is valid even when it’s disabled…

3 Likes

I asked a similar question related to Python debug Hope it helps.