Why is &array[0] @safer than array.ptr?
David Nadlinger via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jan 25 15:09:11 PST 2017
On Wednesday, 25 January 2017 at 22:54:32 UTC, Adam D. Ruppe
wrote:
> On Wednesday, 25 January 2017 at 22:46:10 UTC, David Nadlinger
> wrote:
>> This is because every pointer in SafeD is dereferencable.
>
> But null pointers are allowed in SafeD and arr.ptr is either
> arr[0] or null....
This is a fallacy:
---
@safe: // Deprecated, though.
ubyte oops(ubyte[] b) {
return *b.ptr;
}
void main() {
oops(new ubyte[0]);
// - or -
auto b = new ubyte[42];
oops(b[$ .. $]);
}
---
— David
More information about the Digitalmars-d-learn
mailing list