[fpc-devel] Managed Types, Undefined Bhaviour

Willibald Krenn Willibald.Krenn at gmx.at
Sat Jul 7 19:47:30 CEST 2018


>Gesendet: Samstag, 30. Juni 2018 um 13:34 Uhr
>Von: "Florian Klämpfl" <florian at freepascal.org>

Sorry for the late reply.

>> In an ideal world, either the language would not let you write code that has random behavior or the compiler would enforce this.
>
>Compile with trunk and -Sew and you get this behavior.

Thanks, interesting to know. A very useful feature - should be on by default.
That said, I'm using fpc to develop an application I need for resource planning, hence I cannot use non-relase versions of fpc that might not even be working with Lazarus.


>> Out of curiosity I did a couple of more tests and it seems FPC is pretty inconsistent in handling all this. See below.
>
>Pretty useless code fragment.
>1) This is fpc-devel and not lazarus-same-random-code, it does not compile without lazarus and even not with it.
>2) If I guess the missing parts right, the example simply points out a bug of the setlength handling which is handled
>internally but this is fixed now.

The only thing it had demonstrated is that the funky behaviour only occurs when global vars are being used. In all other cases (also if the array is part of a record) a more sane behaviour is there. Which seems interesting to me. (From a language design point of view.) If it helps, I can easily supply you with a console-type version of this - it's a super-trivial example. 

In any case, I won't push this any further, as there clearly is no support from anybody else for letting the compiler properly initialize managed types (was thinking about a mode switch) and since it's documented undefined behaviour, Delphi compatibility cannot really be achieved either. And with the new -Sew switch it seems that FPC will warn about or fail to compile code that will result in random, undefined behaviour anyways.

Best,
 Willibald




More information about the fpc-devel mailing list