arr.ptr, @safe and void*

Nick Treleaven via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jun 15 13:08:50 PDT 2016


On Wednesday, 15 June 2016 at 17:35:49 UTC, Steven Schveighoffer 
wrote:
> On 6/15/16 6:32 AM, Nick Treleaven wrote:
>>
>> My question is: would returning void* instead really be 
>> unsafe, i.e. is
>> there a way of dereferencing it in safe code? (I'm not 
>> thinking about
>> holes in @safe, but ways by design).
>
> Yes. If the meaning of this expression is different in @safe 
> vs. @system, then compiler inference can affect code 
> drastically:
>
> auto d = arr1.ptr - arr2.ptr;

I probably wasn't clear - I'm not suggesting .ptr returns void*, 
I agree with you. But I don't get why arr.ptrValue can't be safe 
and return void* instead of uintptr_t.

> The PR I think you are referring to is mine: 
> https://github.com/dlang/druntime/pull/1592
>
> And this would be able to solve the problem, but I don't know 
> if it's ready for prime time (proposed to be in core.internal).

I did see this, it's interesting. I suppose the advantage over 
ptrValue would be type safety.



More information about the Digitalmars-d-learn mailing list