@safe inference fundamentally broken

deadalnix via Digitalmars-d digitalmars-d at puremagic.com
Thu Jun 5 14:37:37 PDT 2014


On Thursday, 5 June 2014 at 20:37:51 UTC, Steven Schveighoffer
wrote:
> On Thu, 05 Jun 2014 16:32:24 -0400, monarch_dodra 
> <monarchdodra at gmail.com> wrote:
>
>> On Thursday, 5 June 2014 at 19:57:08 UTC, Steven Schveighoffer 
>> wrote:
>>> A possible fix could be to reject the call to ptr at runtime 
>>> if the slice is empty.
>>
>> I don't know why you'd ever do "arr.ptr" in the first place, 
>> other than to avoid the bounds check. So I think the call 
>> should just be unsafe, and we call it a day. Or maybe to 
>> interface with a function that want a pointer?
>
> That's true. You can always get a pointer to any valid element 
> with &arr[x]. Then at least you have bounds checking to save 
> you.
>
> In fact, in safe code, arr.ptr could be replaced with &arr[0].
>

&arr[0] does bound checking. That is different ;)


More information about the Digitalmars-d mailing list