[fpc-pascal] SetLength warnings - request

Jonas Maebe jonas at freepascal.org
Wed Jan 2 18:46:00 CET 2019


On 02/01/19 18:31, Martok wrote:
> Am 02.01.2019 um 17:23 schrieb Sven Barth via fpc-pascal:
>> 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.
> 
>> Anything else can potentially be a bug lying in wait.
> Again, why is this not changed?
> 
> Clearly we can't change Delphi, but there is no real reason not to be better
> than them. And it *is* undocumented for them, so we'd still be compatible, just
> compatible-on-the-safe-side.

Then we will get bug reports that FPC is slower than Delphi and 
generates more code, because it will have to allocate and 
initialise/finalise a separate temp instead of just passing an existing 
one without doing anything. Possibly followed by assigning this existing 
temp to its final destination after the function call, instead of 
directly passing the target as function result (for which we also have 
received bug reports in the past).


Jonas



More information about the fpc-pascal mailing list