Apart from the assembler output for enums, which are read only:
.section .rodata.n_RTTI_$P$ENUMS_$$_DAY,"aw"
.balign 8
.globl RTTI_$P$ENUMS_$$_DAY
RTTI_$P$ENUMS_$$_DAY:
.byte 3,3
.ascii "day"
.quad 0
.byte 1
.long 0,6
.quad 0
.byte 6
.ascii "monday"
.byte 7
.ascii "tuesday"
.byte 9
.ascii "wednesday"
.byte 8
.ascii "thursday"
.byte 6
.ascii "friday"
.byte 8
.ascii "saturday"
.byte 6
.ascii "sunday"
.byte 5
.ascii "enums"
.byte 0
Furthermore, an external library does not even export the enum names! only the ordinal values in a set.
I would like you to look at the example I gave for the switch.
type
my_engine = (off,slow,fast); //constant values 0,1,2
their_enginemod = (reverse, neutral, off);//constant values 0,1,2
How will my engine behave? The code relies on their constant index.....
So after the mod it is not off but goes in reverse....
Sets, on the other hand,
do have a variable nature (although they can be declared as const) but indeed require that the full range is known.
The most important part about enums is that they are ordered and their order
can not change. Their member ordinal value (index) is
fixed and the compiler makes them compile-time
constants.
Play with this:
library enumlib;
type
myenum = (what,would, be, my, index);
function enumtest:myenum;
begin
enumtest := index;
end;
exports
enumtest;
end.
program enums;
{$mode delphi}
{$linklib 'enumlib'}
type
myenum = (what,would, be, my, index); // must be known....
function enumtest:myenum; externaL;
begin
writeln(enumtest);
end.
And tell me what happens?
Your main program needs to
know the full enum to work as enum, now, doesn't it?
Otherwise you'll end up with
program enums2;
{$mode delphi}{$linklib 'enumlib'}
function enumtest:integer; externaL;
begin
writeln(enumtest);
end.
Still works without enum, gives the index(4) instead.
That is because an enum is an
ordinal value.
I can't make it any clearer than this.
Bonus lib:
library enumlib2;
type
// can't export a type!
myenum = (what, would, be, my, index);
var
// can export a set! but enum type needs to be known at the other side
enumset:set of myenum = [what,would, be, my, index];export name 'enumset';
exports
enumset;
end.