# Has \`undef\` lost its undefedness?

**URL:** <https://discourse.julialang.org/t/has-undef-lost-its-undefedness/12335>\
**Category:** General Usage\
**Created:** [July 12, 2018, 3:25pm UTC](https://discourse.julialang.org/t/has-undef-lost-its-undefedness/12335 "2018-07-12T15:25:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dmbates](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dmbates/32/44_2.png) [@dmbates](https://discourse.julialang.org/u/dmbates)\
**Post date:** [July 12, 2018, 3:25pm UTC](https://discourse.julialang.org/t/has-undef-lost-its-undefedness/12335/1 "2018-07-12T15:25:33Z")

</div>

I had thought that current practice is to initialize arrays to `undef` and to test if values has been assigned with `isassigned`. On

```julia
julia> versioninfo()
Julia Version 0.7.0-beta.276
Commit 70bd2c2116* (2018-07-12 12:55 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: Intel(R) Core(TM) i5-3570 CPU @ 3.40GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.0 (ORCJIT, ivybridge)

```

I get

```julia
julia> tt = Matrix{Int}(undef, (2,5))
2×5 Array{Int64,2}:
 0 0 0 0 0
 0 0 0 0 0

julia> similar(tt)
2×5 Array{Int64,2}:
 139787846964720 1 139787846964880 4 2
 139787846964640 139787846964800 139787846964960 3 139787817320961

julia> isassigned(tt, 1)
true

```

in contrast to what I read in the documentation for `isassigned`.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [July 12, 2018, 3:28pm UTC](https://discourse.julialang.org/t/has-undef-lost-its-undefedness/12335/2 "2018-07-12T15:28:50Z")

</div>

The `#undef` values in arrays are only for “pointer types” that cannot be stored in arrays inline, like mutable structs and such. Bits types have always just given you uninitialized memory in this situation.

---

<div class="post-metadata">

**Author:** ![dmbates](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dmbates/32/44_2.png) [@dmbates](https://discourse.julialang.org/u/dmbates)\
**Post date:** [July 12, 2018, 3:32pm UTC](https://discourse.julialang.org/t/has-undef-lost-its-undefedness/12335/3 "2018-07-12T15:32:44Z")

</div>

Okay, that makes sense. I seem to recall being given deprecation warnings about e.g. `Vector{Int}(20)`, which should be changed to `Vector{Int}(undef, 20)`. That seems a bit hard line if the `undef` has no effect.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [July 12, 2018, 3:37pm UTC](https://discourse.julialang.org/t/has-undef-lost-its-undefedness/12335/4 "2018-07-12T15:37:07Z")

</div>

We don’t want exposing undefined memory to be a silent default. The `Vector{Int}(n)` constructor will be reclaimed in the future: in general, `Vector(x)` will construct a vector by iterating `x` and `Vector{T}(x)` will construct a `Vector{T}` by iterating `x`.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [July 12, 2018, 8:42pm UTC](https://discourse.julialang.org/t/has-undef-lost-its-undefedness/12335/5 "2018-07-12T20:42:54Z")

</div>

> [@dmbates](#):
>
> `undef` has no effect

Strictly speaking, how can you tell if it has no effect (with bits types)? It is literally undefined, so it may as well be `0` or equivalent. You just can’t rely on it.
