ImportC and nothrow/@nogc?
Paulo Pinto
pjmlp at progtools.org
Thu Aug 22 06:54:07 UTC 2024
On Tuesday, 20 August 2024 at 00:30:46 UTC, Richard (Rikki)
Andrew Cattermole wrote:
>
> On 20/08/2024 12:24 PM, Gregor Mückl wrote:
>> On Sunday, 18 August 2024 at 09:42:16 UTC, Nicholas Wilson
>> wrote:
>>> On Sunday, 18 August 2024 at 04:43:34 UTC, Manu wrote:
>>>> [...]
>>>
>>> Well, C may call C++ which may throw. It is very unlikely to
>>> call the GC however.
>>>
>>> I don't think it would be hard to add a switch that
>>> "`extern(C)` functions being called from import C are
>>> `@nogc`".
>>
>> Here's what I'm thinking:
>>
>> The C function interface has no notion of C++ exceptions
>> (AFAIK it's following C specs, not C++), so C++ exceptions
>> should not even be a consideration at that point. I do not
>> think that throwing a C++ exception up a stack that contains
>> extern(C) functions is even properly defined behavior on the
>> C++ side. In other words, all ImportC declarations should be
>> implicitly @nothrow.
>
> Its defined for MSVC:
>
> https://learn.microsoft.com/en-us/cpp/cpp/structured-exception-handling-c-cpp?view=msvc-170
>
> "Structured exception handling (SEH) is a Microsoft extension
> to C and C++ to handle certain exceptional code situations,
> such as hardware faults, gracefully."
>
> I'm pretty sure for other platforms it is also defined as part
> of unwinding, although I can't be bothered to hunt for the
> specification. It's not about C, it's about languages that are
> not C++ (consider JIT's for instance).
That is a special case, given how C++ is relevant in the
Microsoft ecosystem, and SEH existence, you won't find that in
other platforms, not even on UNIX where C++ was born alongside C.
I am not even sure that is even covered on Itanium ABI that most
modern compilers have meanwhile adopted on remaining UNIX
platforms.
More information about the Digitalmars-d
mailing list