56
Programming with TIDE
©2000-2008 Tibbo Technology Inc.
Monday). Note that even though Monday is an
(i.e., an actual word,
and not just some number) it does not have to be surrounded by quote marks
(because it's not a string).
The value associated with each identifier within the enumeration type doesn't
necessarily have to be unique; however, when you associate the same value with
several constants, the distinction between these constants will be lost on compile
time.
enum
dayofweek
Sunday =
1
,
Monday,
Tuesday,
Wednsday,
Thursday,
Friday,
Saturday,
holiday =
99
bestdayofweek =
7
' bestdayofweek and Saturday are actually the
same!
fridaythethirteenth = -
666
' a negative constant.
end
enum
Note that above,
saturday
was implicitly (automatically) associated with the value
7, and
bestdayofweek
was explicitly associated with the same value. Now, on
compile-time, they would both be considered to be just the same.
Type Mapping for Enum Types
When the project is being compiled, all enumeration types are substituted with
plain numerical values. the platform on which the code is running doesn't have to
know anything about Saturday or about the best day of the week; for the platform,
the number 7 is informative enough.
Hence, enumeration types are converted to various built-in numerical variable
types. The actual numerical type used to store the enumeration type depends on
the values associated with the constants within this enumeration type:
Values associated with constants
do not exceed range
Actual variable type used to store
enum type
-128 to 127
char
0 to 255
byte
-32768 to 32767
short
0 to 65535
word
-2147483648 to 2147483647
long
0 to 4294967295
dword
Notice, that enumeration types cannot be converted into real values, so you cannot
use fractional numbers in you enums.
Some examples:
132