Calling D from C

Alex Rønne Petersen xtzgzorex at gmail.com
Mon Mar 12 07:56:42 PDT 2012


On 12-03-2012 15:53, Chris W. wrote:
> I have a problem when calling D functions from C. While I can
> perform simple arithmetic operations (i.e. the calculation is
> performed in D and returned to C), I experience problems when
> trying to perform string/char operations or call functions from
> the D standard library (e.g. writefln()). The usual error message
> I get is either "Bus error" or "Segmentation fault". I haven't
> been able to find the reason for this. The programs compile and
> link, however, when run, they terminate with "Bus error" whenever
> a D function is performed within the D code, e.g. something like
> char[] s2 = s.dup; (s is a char* passed from C). Any hint or help
> would be appreciated.
>
> I am using Mac OS X, 10.6.7

Are you remembering to initialize the runtime, attach your thread, 
etc... Also, you can't call D functions directly from C code. You have 
to go through an extern (C) wrapper that then calls the D function.

-- 
- Alex


More information about the Digitalmars-d mailing list