[fpc-devel] Dangerous optimization in CASE..OF

Michael Van Canneyt michael at freepascal.org
Mon Jul 3 08:28:27 CEST 2017



On Sun, 2 Jul 2017, Tomas Hajny wrote:

>
>> By using file of enum (or any data type), you are explicitly telling the
>> compiler it is OK.
>
> There isn't much difference between telling the compiler that all values
> in certain file are of certain type and telling the compiler that the next
> value read from that file (text in this case) will conform to certain
> type. Both is typed, both should provide means for ensuring type safety
> while loading the value to the variable of the given type.

I think 'both are typed' is not correct. When reading from a text file, the
RTL is explicitly performing a conversion from text to string/float/integer.

The whole point of "File of enum" is exactly that no such conversion is
necessary, because you know the file contains only enum values.

If you don't know this for sure, then you must use file of integer instead
and check&convert the values.

>
> Note that I don't talk about typecasting here, of course, that's something
> completely different (and manual checking is absolutely appropriate
> there).

In my opinion, the whole point is moot. 
I think this kind of check is entirely unnecessary given the definition, as
I have argued. If that argument fails to convince you, so be it.

If you do implement a check for reading enums (or other types) from a typed file, 
then please make sure it is only under $R+

Michael.



More information about the fpc-devel mailing list