I’m just curious since Julia uses 1-based indexing.
E.g.
julia> @enum Color Red Blue
julia> Red
Red::Color = 0
julia> Blue
Blue::Color = 1
I’m just curious since Julia uses 1-based indexing.
E.g.
julia> @enum Color Red Blue
julia> Red
Red::Color = 0
julia> Blue
Blue::Color = 1
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> @enum Color Red=1 Blue
julia> Red
Red::Color = 1
julia> Blue
Blue::Color = 2
potentially because Enum might be used with Ccall to map some friend Enums
This was already discussed: Why is @enum 0-based?