# Why does the first enum member value default to zero instead of one?

**URL:** <https://discourse.julialang.org/t/why-does-the-first-enum-member-value-default-to-zero-instead-of-one/87219>\
**Category:** Internals & Design\
**Tags:** enum\
**Created:** [September 13, 2022, 3:27pm UTC](https://discourse.julialang.org/t/why-does-the-first-enum-member-value-default-to-zero-instead-of-one/87219 "2022-09-13T15:27:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mthelm85](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mthelm85/32/224164_2.png) [@mthelm85](https://discourse.julialang.org/u/mthelm85)\
**Post date:** [September 13, 2022, 3:27pm UTC](https://discourse.julialang.org/t/why-does-the-first-enum-member-value-default-to-zero-instead-of-one/87219/1 "2022-09-13T15:27:17Z")

</div>

I’m just curious since Julia uses 1-based indexing.

E.g.

```julia
julia> @enum Color Red Blue

julia> Red
Red::Color = 0

julia> Blue
Blue::Color = 1

```

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [September 13, 2022, 4:03pm UTC](https://discourse.julialang.org/t/why-does-the-first-enum-member-value-default-to-zero-instead-of-one/87219/2 "2022-09-13T16:03:26Z")

</div>

Well, the underlying numbers of a `@enum` are not related to indexing (it cannot be used for it unless you explicitly convert it, or create a new `getindex` method), so there is no reason why not start at the first unsigned number.

You can define the starting value (or all values) of a `@enum` explicitly:

```julia
julia> @enum Color Red=1 Blue

julia> Red
Red::Color = 1

julia> Blue
Blue::Color = 2

```

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [September 13, 2022, 5:34pm UTC](https://discourse.julialang.org/t/why-does-the-first-enum-member-value-default-to-zero-instead-of-one/87219/3 "2022-09-13T17:34:20Z")

</div>

potentially because Enum might be used with Ccall to map some friend Enums

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [September 13, 2022, 6:13pm UTC](https://discourse.julialang.org/t/why-does-the-first-enum-member-value-default-to-zero-instead-of-one/87219/4 "2022-09-13T18:13:57Z")

</div>

This was already discussed: [Why is @enum 0-based?](https://discourse.julialang.org/t/why-is-enum-0-based/12722)
