[fpc-pascal] SetLength warnings - request
pascaldragon at googlemail.com
Wed Jan 2 17:23:47 CET 2019
Am Mi., 2. Jan. 2019, 17:05 hat Benito van der Zander <benito at benibela.de>
> The non-initialization of 'Result' has bitten me more than once in Delphi.
> Me, too. Usually the solution was to add a call to SetLength.
> That makes the bullshit hints especially bad.
Even in Delphi situations can occur where a dynamic array Result variable
is non-Nil already upon entry and then SetLength will simply manipulate
that preexisting array instead of working on a new array. In most cases
that probably won't have a real effect as the array is either set to empty
anyway or all it's elements are initialized by the function. That doesn't
change the fact however that the behavior *is* there and can potentially
lead to hard to debug problems.
The only exception for the warning could possibly be SetLength(Result, 0)
as that is the equivalent of "Result := Nil" or "Result := " as 3.2.0 now
Anything else can potentially be a bug lying in wait.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the fpc-pascal