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

Florian Klämpfl florian at freepascal.org
Sun Jul 2 20:18:47 CEST 2017


Am 02.07.2017 um 20:12 schrieb Martok:
>> They are:
>> http://docwiki.embarcadero.com/Libraries/XE5/en/System.Boolean
> That prototype is a recent invention, it wasn't there in older versions. Also

*sigh* This is the case since pascal was iso standarized.

> the text sounds quite different somewhere else:
> http://docwiki.embarcadero.com/RADStudio/XE5/en/Simple_Types#Boolean_Types
> 
>> Yes. What I wanted to point out: also delphi does optimizations on enums which fails if one feeds
>> invalid values.
> Okay, if you want believe that Booleans are enums:

I do not believe, I know.

> 
>   b:=boolean(42);
>   if not b then
>     writeln('falsy')
>   else
>     writeln('truthy');
> 
> Prints truthy. Doesn't crash.

Yes, undefined behavior.



More information about the fpc-devel mailing list