# Undef for Array and SharedArray initialisation

**URL:** <https://discourse.julialang.org/t/undef-for-array-and-sharedarray-initialisation/14366>\
**Category:** General Usage\
**Created:** [August 31, 2018, 2:26pm UTC](https://discourse.julialang.org/t/undef-for-array-and-sharedarray-initialisation/14366 "2018-08-31T14:26:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [August 31, 2018, 2:26pm UTC](https://discourse.julialang.org/t/undef-for-array-and-sharedarray-initialisation/14366/1 "2018-08-31T14:26:16Z")

</div>

I feel like I’m a bit late to the party on this one but I’m only now getting around to updating some code originally written in Julia 0.3, and was surprised to see this:

`Array{Float64}(100)` now raises a warning telling me to use `Array{Float64}(undef, 100)` instead. I’ve found the reference in the docs, but still don’t quite understand why `undef` is now required.

However, upon updating all my code I also made this change to a `SharedArray` constructor, to find that this raises an error as `SharedArray` doesn’t have a method that includes the `undef` argument. Can someone explain the reasoning behind this?

(NB this is all on Julia 0.7.0 on Win10)

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [August 31, 2018, 3:14pm UTC](https://discourse.julialang.org/t/undef-for-array-and-sharedarray-initialisation/14366/2 "2018-08-31T15:14:09Z")

</div>

`Array{T}(100)` has always created an array filled with uninitialized memory, but that wasn’t particularly obvious from the syntax. Providing the `undef` arg makes that more obvious and also provides a way to specify other kinds of initializations in the future.

I think SharedArray has its own `init` arg to control initialization, although it would be nice for it to share the same API.

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [August 31, 2018, 3:18pm UTC](https://discourse.julialang.org/t/undef-for-array-and-sharedarray-initialisation/14366/3 "2018-08-31T15:18:20Z")

</div>

For all the gory details: [https://github.com/JuliaLang/julia/issues/24595](https://github.com/JuliaLang/julia/issues/24595)

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [September 5, 2018, 9:39am UTC](https://discourse.julialang.org/t/undef-for-array-and-sharedarray-initialisation/14366/4 "2018-09-05T09:39:58Z")

</div>

Great thanks, I’ve [opened an issue](https://github.com/JuliaLang/julia/issues/29046), as I think aligning the API here would be a useful change to make.
