On Wednesday, April 16, 2025 8:48:04 AM MDT H. S. Teoh via Digitalmars-d-learn 
wrote:
> On Wed, Apr 16, 2025 at 04:23:43AM +0000, Andy Valencia via 
> Digitalmars-d-learn wrote:
> > On Wednesday, 16 April 2025 at 01:44:33 UTC, Paul Backus wrote:
> > > Nope, you're not missing anything. Using pointers is totally normal
> > > and idiomatic in D.
> >
> > That said, I try to code under @safe when I can, and let the compiler
> > guide me clear of a whole class of C-type potential bugs.
> [...]
>
> Pointers can be used perfectly fine in @safe. Just not unsafe operations
> like pointer arithmetic.

Also, taking the address of stuff like local variables is @system, because
it's not safe if the pointer escapes. But yeah, in general, using pointers
is @safe outside of pointer arithmetic. At that point, there isn't much
difference between a pointer and a reference. They just point to an object.
It's escaping which is potentially a problem (which ref is stricter about)
and pointer arithmetic (which can't be done with ref). Basically, as long as
what you're doing with a pointer is what can be done with a reference, then
it's @safe.

- Jonathan M Davis



Reply via email to