[fpc-devel] [Suggestion] Enumeration range-check intrinsic
Jonas Maebe
jonas at freepascal.org
Sat Jul 6 15:19:21 CEST 2019
On 06/07/2019 14:56, Martok wrote:
> Am 06.07.2019 um 09:01 schrieb Ondrej Pokorny:
>> Ord(aEnum) for invalid enumeration values is undefined ;)
>
> If there was any logic here, it should be, but it's not ;-)
>
> The documentation page specifically mentions Ord as the older syntax to hard
> casts. Whatever it contains, any enum is always smaller or equal to the largest
> possible bitsize, which is Longint.
It is in fact undefined. The undefined behaviour comes from the fact
that an invalid value was stored in the variable and then read again,
not from how the read value is used. An example of where you may get
different data than wat you put in, even in the absence of any
optimisations, is again bitpacked records/arrays.
Jonas
More information about the fpc-devel
mailing list