Skip to content
Prev 16628 / 63424 Next

Calling C from Fortran

(Forgot to post.) Yes, that was a typo, and the reason is the same; the C
function expects a value rather than its address. That's why you can't use
it directly from Fortran (aside from naming issues) but it's fine in C.

Reid Huntsinger

-----Original Message-----
From: Gilles GUILLOT [mailto:gilles.guillot at inapg.inra.fr] 
Sent: Wednesday, June 15, 2005 11:50 AM
To: R-devel at lists.R-project.org
Cc: Huntsinger, Reid
Subject: Re: [Rd] Calling C from Fortran


Thanks for your reply.

Am I write if I say that the wrapper shoul be 
double F77_SUB(mygammafn)(double *x) { return gammafn(*x); }

instead of 
double F77_SUB(mygammafn)(double *x) { return gammafn(x); }

the first does not compile.
wrapper2.c: In function `mygammafn_':
wrapper2.c:6: error: incompatible type for argument 1 of `Rf_gammafn'

The second compiles and works fine.


But still,  I find it very strange as the C function gammafn actually called

( as I can see from /R-2.1.0/src/nmath/gamma.c)
is not defined as
double gammafn(double *x)

but as
double gammafn(double x)

Am I missing something ?

Gilles 


Le Mercredi 15 Juin 2005 17:06, vous avez ?crit :
---------------------------------------------------------------------------
---------------------------------------------------------------------------