September 29, 2006
Hi, I'm trying to access some complex number routines from C, but I can't get it to work (using 0.167 on linux). Here is some sample code:

extern (C)
{
    creal cexpl(creal); // e^x
    real  cabsl(creal); // |x|
}

As I understand, 'real' is equivalent to 'long double' in C, and 'creal' to 'long double complex', so this should work. But when I try it:

writefln( cabsl(3+4i) ); // Works, outputs 5
writefln( cexpl(1+0i) ); // Segmentation fault

In general, passing creal arguments and returning reals works, but returning creals segfaults. Why doesn't this work? Does gcc do something fancy with complex types in the C libraries?

Nick