Created attachment 1571 [details] D and C code files along with makefile Trying to call D code from C is resulting in segfault.
(In reply to Puneet Goel from comment #0) > Created attachment 1571 [details] > D and C code files along with makefile > > Trying to call D code from C is resulting in segfault. Kindly see the attachment to look at the code that segfaults.
Reduced the test case a little: main.c: ---- extern void initialize(); int main(int argc, char*argv[]) { initialize(); return 0; } ---- foo.d: ---- extern(C) void initialize() { import core.runtime; Runtime.initialize; int x; auto dg = {x = 2;}; Runtime.terminate(); } ---- Compiling and running: ---- $ gcc -c main.c $ dmd foo.d main.o $ ./foo Segmentation fault (core dumped) ----
I think the problem is that the memory for the closure is allocated as soon as the initialize function is entered, i.e. before the call to Runtime.initialize.
I cannot reproduce this example. Compiling the reduced test case and running it now leads to graceful program exit.