Bug 4710 – writeln crashes when called from C code.

Status
RESOLVED
Resolution
INVALID
Severity
major
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Mac OS X
Creation time
2010-08-22T01:44:00Z
Last change time
2012-09-12T21:30:35Z
Assigned to
nobody
Creator
kennytm

Comments

Comment #0 by kennytm — 2010-08-22T01:44:15Z
Given the following content: // x.d import std.stdio; extern (C) void foo() { writeln("1"); } // y.c void foo(void); int main () { foo(); return 0; } And compile and run with gcc -c -m32 y.c -o y.o dmd x.d y.o -ofx ./x Result in a Bus Error on Mac OS X. (I am using dmd r620, druntime r370 and Phobos r1900.)
Comment #1 by verylonglogin.reg — 2012-09-12T21:30:35Z
When calling from C you have to explicitly initialize D's runtime first. Your program calls Phobos function on uninitialized druntime and will obviously crash. For more information read this: http://stackoverflow.com/questions/7480046/implementing-a-c-api-in-d/7486417#7486417