How to use @safe when a C library integration needed

Leonardo leotada523 at gmail.com
Fri Apr 14 14:10:41 UTC 2023


On Monday, 23 January 2023 at 16:46:48 UTC, Dom DiSc wrote:
> 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).

Thanks. But this works only to one function per time. Is there 
any way to do this to an imported library at all? something like 
`@trusted import library`


More information about the Digitalmars-d-learn mailing list