Why is &array[0] @safer than array.ptr?
David Nadlinger via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jan 25 15:21:00 PST 2017
On Wednesday, 25 January 2017 at 22:59:55 UTC, Jonathan M Davis
wrote:
> Yes, but my point is that you're normally only going to use
> .ptr to pass something to a C function, and even if you're
> doing more with it in D, odds are, you're going to be doing
> pointer arithmetic.
Wrong again. If this were the case, we wouldn't have needed to
make it a deprecation at all, since all uses would have been
mistakes. A non-negligible amount of real-world D code actually
uses single-object pointers. Look up the change history if you
are interested – and indeed, making sure one understands the
topic sufficiently well to meaningfully contribute before typing
out a wall-length sermon would collectively save us a good chunk
of time.
> And when you combine it with marking C function @trusted, this
> is actually pretty bad.
Ex falso quodlibet – once you have a piece of code mistakenly
marked @trusted, all guarantees are out of the window even
without suspicious-looking client code. @safe-ty is about
mechanically verifiable code, not faith-based programming.
— David
More information about the Digitalmars-d-learn
mailing list