What should happen here?

Steven Schveighoffer schveiguy at gmail.com
Mon Sep 20 18:51:23 UTC 2021


On 9/20/21 2:39 PM, IGotD- wrote:
> On Monday, 20 September 2021 at 18:26:59 UTC, Steven Schveighoffer wrote:
>> Without any context, what do you think should happen here?
>>
> 
> Is this a trick question?

Of course it's a trick question! No normal questions are asked this way ;)

> 
> In a perfect world I think option 1 should happen.
> 
> However doesn't it depend on how the compiler decide what to do with 
> variable c. It can be in a register or it can be on stack. If it is on 
> stack, then the GC believe it is still in use. If it is in a register, 
> then the compiler is likely to optimize c away before the loop and the 
> GC destroys it.
> 
> In reality, I guess option 4.
> 

You are kind of right. The question I bring up, just posted, is how do 
you solve passing a class reference into a C library that should only be 
used during the function?

-Steve


More information about the Digitalmars-d mailing list