How does nil values work --- for example, as the default "zero" value for multiple types?

From Odin Overview - Zero Values,

The zero value is:

  • nil for pointer, typeid, and any types.

nil is used as zero value for many other types other than pointers:

For Enum, it is not documented in the Odin Overview - Enumerations that nil value can be used as zero value of an Enum. So, I thought the integer 0 is the only zero value of Enum because Enum already has a zero value (integer 0), so there is no need for another zero value.

But the examples in Odin Overvew - or_return show that nil can be used to compare a Enum variant with value 0.

So, my questions are:

  1. How does nil value fundamentally work?

  2. Is is just 0 under the hood, i.e., the memory completely zeroed out?

  3. Where all can we use nil?

  4. Differences between using nil and {}?

I am not quite sure, but I think nil and 0 are equivalent vor enums. There is also an open issue because of the ambiguity in switch cases.

The documentation/overview needs to be updated to explain and clarify the concept of nil behind enums and the difference to unions where nil means nothing/undefined aka absence of a value.

But the zero value for enums can also either be a real enum case or an invalid one, for example when the first case starts with 1 , or when the enum has no cases at all.

package main

import "core:fmt"

Direction0 :: enum {
    North, East, South, West,
}

Direction1 :: enum {
    North = 1, East, South, West,
}

main :: proc() {
    d0: Direction0 // = {}
    fmt.println("d0:", d0 == nil, int(d0), d0)
  
    d1: Direction1 // = {}
    fmt.println("d1:", d1 == nil, int(d1), d1)
}

prints:

d0: true 0 North
d1: true 0 %!(BAD ENUM VALUE=0)