cast(string) for mutable array
Nick Treleaven
nick at geany.org
Fri Jul 31 21:32:03 UTC 2026
On Friday, 31 July 2026 at 13:52:12 UTC, Vindex9 wrote:
> ```d
> string fn() @trusted pure {
> char[] arr;
> // some manipulations...
> return cast(string) arr;
> }
> ```
>
> Where is the line between cases where the `@trusted` tag can be
> used and cases where the `@system` tag can be used?
`@trusted` must have a memory-safe interface. So if the elements
of `arr` cannot be accessed as mutable after the cast, it is OK
to use `@trusted` to cast them to immutable.
`@system` is used for a function which does not have a safe
interface (e.g. one that accepts a `char*` parameter pointing to
a C zero-terminated string).
More information about the Digitalmars-d-learn
mailing list