Enumeration Types
An enumeration is a group of related constants. Unless specified otherwise, constants in the group are automatically assigned incrementing values, counting from 0.
As a result of the enumeration definition, a new variable type is created. You can then define other variables of this type.
Members defined in the enumeration construct are independent constants.
Enumeration Types in Tibbo BASIC
'the definition
enum dayofweek
DOW_UNKNOWN, '0
DOW_SUNDAY, '1
DOW_MONDAY, '2
DOW_TUESDAY, '3
DOW_WEDNESDAY, '4
DOW_THURSDAY, '5
DOW_FRIDAY, '6
DOW_SATURDAY, '7
DOW_HOLIDAY = 99, 'explicit value specification
DOW_HOLIDAY2 '100
end enum
sub on_sys_init
dim day as dayofweek 'and now a variable based on the enum type
dayofweek=DOW_FRIDAY
end sub
Enumeration Types in Tibbo C
//the definition enum dayofweek{ DOW_UNKNOWN, //0 DOW_SUNDAY, //1 DOW_MONDAY, //2 DOW_TUESDAY, //3 DOW_WEDNESDAY, //4 DOW_THURSDAY, //5 DOW_FRIDAY, //6 DOW_SATURDAY, //7 DOW_HOLIDAY = 99, //explicit value specification DOW_HOLIDAY2 //100 }; void on_sys_init(){ dayofweek day; //and now a variable based on the enum type dayofweek=DOW_FRIDAY; }
Enumeration Types Are Understood by the Watch and the Parser
Add an enum-type variable to the Watch pane, which will not only show this variable's numerical value, but also the constant associated with it!
The parser also understands enums. Type dayofweek= (for the examples above) and the parser will pop up a list of available choices!
Type Mapping for Enums
When the project is being compiled, all enumeration types are substituted with plain numerical values.
It's not possible to use fractional values in enums.