[fpc-devel] Managed Types, Undefined Bhaviour
sglienke at dsharp.org
Fri Jun 29 19:03:58 CEST 2018
Delphi does not reuse them, every call to a function generates a temp
variable. Sure, if you call it in a loop it of course uses the same one.
But if you have 2 calls after each other the compiler generates two
variables. Even if they are in seperate code branches. I have often
enough optimized some code that caused huge prologue/epilogue just for
temp variables of different calls where only one could have happened
(like in a case statement). You can see exactly that in the answer by
David Heffernan you linked to. The loop keeps adding X while the other
two calls get an empty string passed.
Am 29.06.2018 um 18:27 schrieb Jonas Maebe:
> On 29/06/18 17:57, Stefan Glienke wrote:
>> Now we are back to using temp variables (both Delphi and FPC do) but
>> FPC again reuses its temp variable for A and B while Delphi uses
>> different ones. Now for some integer this might not be a big issue
>> but imagine you have something else in these arrays (for example any
>> managed type like an interface).
>> Not having properly cleared B because it still uses the temporary
>> content from A might cause some issues.
> My point was that Delphi sometimes also reuses temp variables. See the
> StackOverflow posts linked from the previous message. It does not do
> it in the same cases as FPC, but it does do it. So while you may be
> lucky more often in Delphi, relying on this behaviour is unsafe even
> there afaik.
> fpc-devel maillist - fpc-devel at lists.freepascal.org
Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
More information about the fpc-devel