On Monday, 8 August 2022 at 19:33:14 UTC, Steven Schveighoffer wrote:
There's nothing clever. If you want to access C globals, you should use `__gshared`, because that's what it is. Using `shared`, isn't going to save you at all.

Yes, using `shared` does save you.

C might not have a `shared` qualifier, but C programmers still have to think about thread-safety. Calling a C function or accessing a C global always comes with some (possibly implied) contract on how to do it safely from multiple threads (the contract might be: "don't").

`shared` (with `-preview=nosharedaccess`) forces you to think about what the contract is. `__gshared` doesn't.

[...]
Using `__gshared` to share data with C is as safe as using `-boundscheck=on` and sending the array into C which has no such restrictions.

No it's not. C always being unsafe is true but irrelevant. The point is what you can/can't do on the D side.

`-boundscheck=on` - Can't easily mess up on the D side. C side can still mess up.
`-boundscheck=off` - Can easily mess up on the D side.
`shared` - Can't easily mess up on the D side. C side can still mess up.
`__gshared` - Can easily mess up on the D side.

Reply via email to