cast(string) for mutable array
Jonathan M Davis
newsgroup.d at jmdavisprog.com
Mon Aug 3 20:01:38 UTC 2026
On Monday, August 3, 2026 1:54:48 AM Mountain Daylight Time Vindex9 via Digitalmars-d-learn wrote:
> OK, thank you all.
> It's actually not very convenient to think about these things all
> the time. Over the years, I've gotten used to using `@system` by
> default. But now it turns out that you can almost always use
> `@trusted`.
You frequently can, but remember that when you mark something as @trusted,
you're telling the compiler that you've verified that the code is
memory-safe (whereas with @safe, the compiler has verified that). So, if you
mark code with @trusted when it's not actually memory-safe, you make it so
that @safe code can call code which isn't memory-safe, and the @safe code
then isn't actually memory-safe.
So, ideally, you'd do whatever @system stuff you need to do within a
function and encapsulate the @system stuff in a way that you can mark the
function as @trusted and have an API which is memory-safe, but whether you
can do that or not depends on what your code is doing.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list