Using ImportC to augment a big C project with D

Bastiaan Veelo Bastiaan at Veelo.net
Wed Feb 21 12:45:50 UTC 2024


On Tuesday, 20 February 2024 at 18:33:42 UTC, Carl Sturtivant 
wrote:
> 2.
> The C source calls exit() from C's stdlib, and D needs to 
> terminate properly.

What do you mean by "need"? You can call 
https://dlang.org/phobos/core_stdc_stdlib.html#.exit from D:

```d
import std.stdio;

void main()
{
     scope(exit) writeln("Bye");

     import core.stdc.stdlib : exit;
     exit(0);
}

shared static ~this()
{
     writeln(__FUNCTION__);
}
```

Output:
```
onlineapp._sharedStaticDtor_L11_C1
```

So it does run module destructors, but not `scope(exit)` 
statements (which probably makes sense).

I would expect `exit()` called from the C source to have similar 
results.

--Bastiaan


More information about the Digitalmars-d-learn mailing list