[fpc-pascal] SetLength warnings - request
Michael Van Canneyt
michael at freepascal.org
Tue Jan 1 13:15:06 CET 2019
On Tue, 1 Jan 2019, Martok wrote:
>> I'm curious to see them, because all 'issues' reported here can be perfectly
>> repeated (possibly with some modifications) in Delphi.
>> The non-initialization of 'Result' has bitten me more than once in Delphi.
> Aye. But it's rather rare in Delphi and very common in FPC, so not everyone
> might have encountered it (that's how I'm justifying to myself putting it on the
> Portability List instead of starting a Common Mistakes set ;-) ).
>> I can't explain things better than Jonas did. I intend to rework his
>> arguments and introduce them in the language reference manual.
> Feel free to use any of the examples here:
> As you said, Delphi makes some of the same mistakes
They are not mistakes. It is by design.
In pascal, variables (and that includes "Result") are uninitialized.
The compiler only makes sure the RTL does not crash on managed types,
but you still must regard them as uninitialized and initialize them
As long as you do that, there is no problem.
One can discuss whether the 'variables are uninitialized' rule must be abandoned,
and declare that the compiler should initialize all variables with known values,
but that is another discussion.
More information about the fpc-pascal