Reference
CEnum.@cenum — Macro
@cenum EnumName[::BaseType] value1[=x] value2[=y]Create a Cenum subtype with name EnumName and members value1, value2, and so on. It works like Base.@enum, but follows the semantics of C enums:
- several members may share the same value;
EnumName(x)accepts anyxrepresentable inBaseType, not only the values of the named members;- members can be combined with integers and with each other using
==,<,+,-,*,÷,&,|,xor,~,<<and>>. Arithmetic gives an integer of the base type (promoted as usual for integers), not anEnumName.
BaseType must be a primitive integer type. It defaults to Int32, or to the first of UInt32, Int64 and UInt64 that can hold all values if Int32 cannot, which is the choice C compilers make. A member without an explicit value gets the value of the previous member plus one, starting from zero. A value can be any expression that gives an integer or a Cenum, and can use the earlier members of the same enum, as in C: @cenum Flags a=1 b=a<<1 ab=a|b. Members can also be listed in a begin block.
Examples
julia> @cenum Fruit apple=1 orange=2 kiwi=2
julia> orange == kiwi
true
julia> apple | orange
3
julia> @cenum Color::UInt8 begin
red
green
blue = 0x10
end
julia> Integer(green)
0x01CEnum.Cenum — Type
Cenum{T<:Integer}The abstract supertype of all enumerated types defined with @cenum.