[fpc-devel] Re: Testing for..in feature

Michael Van Canneyt michael at freepascal.org
Thu Nov 5 09:42:59 CET 2009

On Thu, 5 Nov 2009, Paul Ishenin wrote:

> Florian Klaempfl wrote:
>> This rtti isn't published for program use but e.g. writeln(<enum>) uses it.
> Yes, I was surprised when I tried to look why writeln gives a runtime error 
> for unexistent element of enum.
> Also I looked at compile - it just checks if enum has jumps and refuses 
> typeinfo() call for it. Why does compiler hides this info?

Because - for one thing - the RTTI functions of the typinfo unit will fail on it.

They expect 0 to be the first value, and count(elements)-1 to be the last,
and everything else between should be valid values.

tmyenum = (a,b,c=-1,D);

does not cope with this. If you want to support succ(), pred() and whatnot,
you'll have to rewrite a large part of the RTL and RTTI stuff, which I think
is such a can of works and so risky, that it isn't worth the effort.
You'll also have to write all possible values, and so on. 
A can of worms you don't want to open.

Such enums should be used only to import some braindead C headers.
Like I said, it's just a set of constants, wrapped in a type.

Maybe we should not name them enumerated.


More information about the fpc-devel mailing list