Why is &array[0] @safer than array.ptr?
Dukc via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jan 26 00:18:44 PST 2017
On Wednesday, 25 January 2017 at 22:59:55 UTC, Jonathan M Davis
wrote:
> So, yes, if all you're planning to do is look at the pointer to
> the first element in the array, then &arr[0] is safer, but odds
> are quite low that that's actually what you're going to do, and
> in all of the other cases, you might as well just use .ptr. So,
> telling folks to go use &arr[0] instead of .ptr doesn't seem
> very helpful to me.
Pehaps it should say something like: arr.ptr is deprecated in
@safe code. Use &arr[0] for checked access or remove the @safe
attribute.
That would make it clear that .ptr is not an issue, only .ptr in
@safe.
More information about the Digitalmars-d-learn
mailing list