borrowed pointers vs ref

Dicebot via Digitalmars-d digitalmars-d at puremagic.com
Tue May 13 06:50:12 PDT 2014


On Tuesday, 13 May 2014 at 13:40:42 UTC, Jacob Carlborg wrote:
> On 13/05/14 15:36, Dicebot wrote:
>
>> There are 2 `scope` uses to think about. One is storage class 
>> and in
>> that context `scope` is more of owned / unique pointer. Other 
>> is
>> parameter qualifier and that one is closer to ref / borrowed 
>> pointer.
>>
>> Main problem about making `ref` borrowed pointer is that you 
>> will need
>> to prohibit storing it in function transitively. This will 
>> need to
>> become invalid code:
>>
>> struct A
>> {
>>     int* ptr;
>> }
>>
>> int* gptr;
>>
>> void foo(ref A a)
>> {
>>     gptr = a.ptr; // error, can't leak borrowed a.ptr into 
>> global context
>> }
>>
>> This feels like too much of a breakage, this is why `scope` 
>> (or `scope
>> ref`) feels more appropriate.
>
> I always though "scope" would behave like that.

Walter's initial post implies that he wanted to re-used `ref` for 
borrowed pointer (which would mean same semantics as `scope` 
parameter qualifier)


More information about the Digitalmars-d mailing list