Why is @enum 0-based?

Because enums aren’t arrays? They are a wrapper for a kind of integer type, and integer types on a computer have values that generally start at 0, especially for unsigned types.

You might as well ask why UInt8 values go from 0 to 255 and not 1 to 256, or why Bool values are equivalent to 0 and 1 rather than 1 and 2.

Indeed, you can define an @enum to be a wrapper around an unsigned integer or a boolean value, in which case starting the numbering at 1 by default would allow fewer possible values. For example, @enum Switch::Bool begin Off; On; end couldn’t work.

15 Likes