This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: Segmentation fault calling fortran function from c
- From: <burnus at ph2 dot uni-koeln dot de>
- To: <asilter79 at hotmail dot com>
- Cc: <burnus at net-b dot de>, <fortran at gcc dot gnu dot org>
- Date: Wed, 4 Jul 2007 17:30:47 +0200 (CEST)
- Subject: Re: Segmentation fault calling fortran function from c
asilter79 wrote:
> int a = 4;
> b = intgerigonder_(a);
>
> integer Function INTGERIGONDER (X)
> integer X
As FX already wrote there is a difference in the argument handling of C
and Fortran. In C call-by-value and in Fortran call-by-reference is used
by default.
Thus you can either pass the address of the variable 'a' to Fortran as FX
suggested: b = intgerigonder_(&a);
or you can tell Fortran to expect a VALUE not a reference:
integer Function INTGERIGONDER (X)
integer, VALUE :: X
The latter is part of the Fortran 2003 and only works with newer
compilers. (I think it is only in GCC 4.3 and not in 4.2.)
Tobias