This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]