On Tuesday, 20 February 2024 at 02:07:45 UTC, Walter Bright wrote:
>#importc now successfully converts function-like C macros to #dlang function templates:
#define ADD(a, b) a + b
is converted to a D function template:
auto ADD(T1, T2)(T1 a, T2 b) { return a + b; }
ImportC is now fantastically useful! However, does Exception connected behavior limit this?
The ImportC documentation says for Exception Handling that "ImportC is assumed to never throw exceptions. setjmp and longjmp are not supported".
I am unclear under what circumstances D throwing exceptions in the presence of ImportC works.
Reading that sentence carefully, it does not seem to imply that exceptions cannot occur in D code linked to C code compiled with ImportC in all cases. Of course if executing D code hasn't got ImportC code in its call chain then exception handling will work. But there are two other cases.
-
I imagine that if C code calls D code which throws and the exception is caught in D code without unwinding the C part of the call stack this is OK. In some sense ImportC did not throw an exception in this case, even though it executed a call chain to do so, which could be interpreted as ImportC throwing an exception.
-
What if D throws an exception that would supposedly unwind the C part of the call stack and be caught from D further up? I might guess this counts as ImportC throwing an exception and so is not OK, but I hope I am wrong.
Could you please explain the actual situation of ImportC in these cases?