[fpc-pascal] Changing var to out in rtl code

Max Vlasov max.vlasov at gmail.com
Sun Nov 21 16:59:49 CET 2010

On Sun, Nov 21, 2010 at 6:37 PM, Sven Barth <pascaldragon at googlemail.com>wrote:

> On 21.11.2010 16:22, Max Vlasov wrote:
>> But is it possible to do the same (partially, gradually or in any other
>> way) for the "legacy" code that keeps the interface compatibility with
>> Delphi. For example TStrignList.Find(const S: string; var Index:
>> Integer): Boolean; declares "var " so my existing fragments expecting
>> just an result from this call, got "Hint: Local variable "Index" does
>> not seem to be initialized" warning. But looking at the implementation
>> details it seems it is safe to change "var Index" to "out Index" and
>> possibly it is also safe for any delphi/lazarus code calling this method
> Here is an old bug report where "var" => "out" is discussed as well:
> http://bugs.freepascal.org/view.php?id=11263
> I suggest you to read all commants to find the one or other pitfall
> regarding this (especially Jonas' comment 19338).
> That said I personally think that TStringList.Find could be changed indeed,
> as it is a) in an objfpc unit and b) the param isn't a reference counted
> one. (But as I'm not a member of the FPC team, I have nothing final/definite
> to say here ^^)
> Regards,
> Sven

Sven, thank for sharing the link. Comment 19338 is indeed interesting, never
thought about such semantic difference. Apart from TStringList.Find. calls I
noticed also  TStream.ReadBuffer calls that appears much frequently with
constructs like TStream.ReadBuffer(ACount, SizeOf(ACount)) also giving the
hints. Hope I'll be strong enough to apply all the initialization changes to
the sources :)

Max Vlasov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20101121/4f052ac6/attachment.html>

More information about the fpc-pascal mailing list