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).

Reply via email to