ImportC and nothrow/@nogc?
Walter Bright
newshound2 at digitalmars.com
Tue Aug 27 22:12:22 UTC 2024
On 8/26/2024 11:29 PM, Jonathan M Davis wrote:
> Yeah. We already have the ability to declare C bindings without importC. The
> normal use case for importC is to "import" actual C code without having to
> write and maintain a bunch of bindings, and realistically, that code is
> going to be implemented as nothrow and @nogc, because normal C code is
> nothrow and @nogc. Yes, it's _technically_ possible to have C functions
> using D features and import them with importC, but who is actually going to
> do that in practice?
Anyone adding D functions to a C code base. This is the "gradual migration"
strategy. I've used it, and C/C++ users do it a lot between C and C++.
> Not treating importC functions as nothrow and @nogc is hurting the intended
> use case for importC without really enabling much. It seems to me that if
> anyone really wants to have C code using the GC or throwing exceptions, they
> can just use C bindings like they've been able to do for many years, whereas
> having importC assume nothrow and @nogc will make the feature work much
> better for the problem that it's actually trying to solve.
You're right, until someone does it and it breaks in some bizarre way.
You and Manu are right, this is a problem. There's got to be a better, correct
solution.
More information about the Digitalmars-d
mailing list