How to use @safe when a C library integration needed

Dom DiSc dominikus at scherkl.de
Mon Jan 23 16:46:48 UTC 2023


On Monday, 23 January 2023 at 16:36:21 UTC, Leonardo wrote:
> Hello. How to use @safe when a C library integration needed?
>
> Everything need a system function...

```d
@safe fn()
{
    // lot of safe stuff

    () @trusted {
        // in this block[*] @system function like extern C can be 
called.
        // you need to make sure the API is used correct
        @assert(/*C_Fun is safe to be used with param1*/);
        @assert(/*C_Fun is safe to be used with param2*/);
        C_Fun(param1, param2);
    }();

    // more safe stuff

}
```

[*] in fact, this is a lambda function that is directly called, 
because real trusted blocks are not allowed (yet).


More information about the Digitalmars-d-learn mailing list