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

Jonas Maebe jonas at freepascal.org
Sat Jul 15 21:06:42 CEST 2017


On 15/07/17 20:52, lazarus at kluug.net wrote:
> On one hand, you try to be very fundamental about enums - you say that 
> only declared enum values are valid. And there is no zero value for 
> TMyEnum. TMyEnum is declared as follows:
> 
> TMyEnum = (one = 1, two);
> 
> TMyEnum is not a number so it cannot be initialized to zero.

I have said from the start that it is possible to store invalid values 
in variables through the use of a.o. pointers (which is what the class 
zeroing does), explicit typecasts and assembly.

> On the other hand you say, it is documented to be declared to zero.

I say that the memory occupied by class instance fields is documented to 
be initialsed with the bit pattern for zero. If the bit pattern zero is 
not a value for a particular type, using a variable of that type while 
it contains that bit pattern is undefined. Just like using a local 
variable without first assigning a valid value to it is undefined

> So 
> you say that an enumeration is an integer value with aliases for number 
> values.

Not anymore than I say that a shortstring is a 2048 bit integer with 
aliases for integer values. It's true that eventually everything is 
expressed in bits. That is, however, completely besides the point when 
it comes to the semantics of a type system.


Jonas



More information about the fpc-devel mailing list