# Does declaring a variable to be constant do anything at all?

**URL:** <https://discourse.julialang.org/t/does-declaring-a-variable-to-be-constant-do-anything-at-all/6029>\
**Category:** General Usage\
**Tags:** question, constants\
**Created:** [September 21, 2017, 5:58pm UTC](https://discourse.julialang.org/t/does-declaring-a-variable-to-be-constant-do-anything-at-all/6029 "2017-09-21T17:58:01Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![aaowens](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aaowens/32/12101_2.png) [@aaowens](https://discourse.julialang.org/u/aaowens)\
**Post date:** [September 21, 2017, 6:14pm UTC](https://discourse.julialang.org/t/does-declaring-a-variable-to-be-constant-do-anything-at-all/6029/3 "2017-09-21T18:14:49Z")

</div>

Besides the constant type which is useful for performance in the global scope, constant values do actually get inlined into functions. For example:

```julia
julia> const a = 5
5

julia> f(x) = a
f (generic function with 1 method)

julia> @code_llvm f(2.)

define i64 @julia_f_60745(double) #0 !dbg !5 {
top:
  ret i64 5
}

julia> a = 12
WARNING: redefining constant a
12

julia> @code_llvm f(3.)

define i64 @julia_f_60760(double) #0 !dbg !5 {
top:
  ret i64 5
}

```

Here we see that you are not getting the speedup for free. Changing the constant is allowed, but the function trusts that you won’t do this and doesn’t check the value again.

---

_[View the full topic](https://discourse.julialang.org/t/does-declaring-a-variable-to-be-constant-do-anything-at-all/6029)._
