Enumeration Types

Top  Previous  Next

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

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

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

tide_button_addwatch

Add an enum-type variable to the Watch pane and the latter 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.