[fpc-pascal] Ordinal casting to enums
Ondrej Pokorny
lazarus at kluug.net
Thu Jun 6 09:19:51 CEST 2024
writeln() converts the ordinal value to the value name and if the entry
is not found, the 107 error is raised.
Ondrej
On 06.06.2024 06:22, Hairy Pixels via fpc-pascal wrote:
> This program below crashes because the value 12 is not in the enum. I was curious though, how does it know this? Does it have to do a linear search through the enum to find the value? I know "succ" fails at compile time because the enum has assignments but how this works at runtime is another question.
>
> type
> Fruit = (apple = 10,
> banana,
> pear = 20,
> citrus);
> var
> f: Fruit;
> i: Integer;
> begin
> i := 12;
> f := Fruit(i);
> writeln(f);
> end;
>
> Regards,
> Ryan Joseph
>
> _______________________________________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
More information about the fpc-pascal
mailing list