www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - very strange segmentation fault interfacing a GSL-function

Hi,

I am currently trying to call functions from the GNU Scientific 
Library (GSL) with my code, and I observed a very strange 
behaviour. The following test-program compiles, but generates a 
Segmentation fault when run.


gsltest.d
--------------------------
import std.stdio;

extern (C) double gsl_sf_hyperg_2F1(double a, double b, double c, 
double x);

void main() {
   double f = 0.0025;
   // The following line causes a crash
   auto ret = f * gsl_sf_hyperg_2F1(1.0, 10.0, 11.0, 1.0 - f / 
0.025);

   // The following line should be identical, but it does not 
cause the seg fault.
   // auto ret = 0.0025 * gsl_sf_hyperg_2F1(1.0, 10.0, 11.0, 1.0 - 
f / 0.025);

   writeln(ret);
}
---------------------------

If you comment out the crashing line and comment in the line 
below, the program runs and returns 0.015681, which is the 
numerically correct result.

To compile and run the code, I used the following command line:

rdmd -L-L/opt/local/lib -L-lgsl -L-lgslcblas gsltest.d


I tested this on Unix and Mac OS X. Can anyone reproduce the 
error and have an idea what is going on?

Cheers,

Stephan
May 15 2012