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

**URL:** <https://discourse.julialang.org/t/does-julia-have-something-like-ifdef-in-c-for-conditional-compile/44721>\
**Category:** General Usage\
**Tags:** question\
**Created:** [August 11, 2020, 1:50am UTC](https://discourse.julialang.org/t/does-julia-have-something-like-ifdef-in-c-for-conditional-compile/44721 "2020-08-11T01:50:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zhangliye](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zhangliye/32/3208_2.png) [@zhangliye](https://discourse.julialang.org/u/zhangliye)\
**Post date:** [August 11, 2020, 1:50am UTC](https://discourse.julialang.org/t/does-julia-have-something-like-ifdef-in-c-for-conditional-compile/44721/1 "2020-08-11T01:50:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)\
**Post date:** [August 11, 2020, 1:55am UTC](https://discourse.julialang.org/t/does-julia-have-something-like-ifdef-in-c-for-conditional-compile/44721/2 "2020-08-11T01:55:37Z")

</div>

Try,

```julia
@static if @isdefined(var)

```

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

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [August 11, 2020, 6:46am UTC](https://discourse.julialang.org/t/does-julia-have-something-like-ifdef-in-c-for-conditional-compile/44721/3 "2020-08-11T06:46:22Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![johnh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnh/32/3615_2.png) [@johnh](https://discourse.julialang.org/u/johnh)\
**Post date:** [August 11, 2020, 6:53am UTC](https://discourse.julialang.org/t/does-julia-have-something-like-ifdef-in-c-for-conditional-compile/44721/4 "2020-08-11T06:53:18Z")

</div>

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

> [@Equivalent of Python if \_\_debug\_\_](https://discourse.julialang.org/t/equivalent-of-python-if-debug/25715):
>
> In Python there is a feature for simple print style debugging to be switched on or off. If you run a Python script with the -O option then if \_\_debug\_\_: print variable, variable, variable Is there an equivalent in Julia? I know you could set a constant to be true or false, bt that involves editing the code to switch on/off the debug lines.
