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

Ondrej Pokorny lazarus at kluug.net
Sun Jul 16 23:36:43 CEST 2017


On 16.07.2017 21:13, Florian Klaempfl wrote:
> Indeed. This proves the exactly point. Undefined behaviour. The code 
> behaves randomly dependent on the compiler used and even the optimizer 
> switches.

OK, I see now: there is a difference between C enums and C++ enums. Your 
example was about C++ enums. My example was about C enums. The C enums 
are defined to allow any integer value, whereas C++ enums are strongly 
typed.

C enums: https://msdn.microsoft.com/en-us/library/whbyts4t.aspx 
https://www.gnu.org/software/gnu-c-manual/gnu-c-manual.pdf
C++ enums: https://msdn.microsoft.com/en-us/library/2dzy4k6e.aspx

I have to admit that Pascal enums are like C++ enums (strong typed) and 
not like C enums. So yes, you are right.

Ondrej



More information about the fpc-devel mailing list