Mail Archives: djgpp/1997/05/09/09:45:55
> I have a package of routines written in Fortran77, and I would like to
> call them from a C program. I'm using GNU's g77 and GNU C.
> If there is somebody who can answer my questions I would be very
> grateful.
> My questions are:
> 1. How can I specify the appropriate calling convention?
You cannot specify it. It is a given fact and there is only one,
call by reference:
C function calls fortran:
main()
{
int i=1;
double f=2.0;
char *string1="Hello";
char *string2=" World";
foo_ ( &i,&f,string1, string2,len1,len2)
}
Fortran :
subroutine foo(i,f,str1,str2)
integer*4 i
real*8 f
character*(*) str1,str2
write(*,*)i,f,str1,str2
return
end
f77 -c f.f
gcc -c c.c
gcc -o c c.o f.o -lf2c
go32 c
It should work under g77 as well as under f77 (f2c)
> 2. What type of name mangling does the f77 compiler use?
fortran functions get an underscore appended.
> 3. Should I have indicate something in the fortran code as well?
No. We are not in the Microsoft world ("Power" Fortran).
> 4. What are the appropriate gcc command-line switches for .f and .c
> files?
> 5. I would like to access variables, arrays in the fortran code as well.
> Does it differs from accessing functions?
I don't think I understand this question.
>
> Please send your answers at 'dobler AT hercules DOT elte DOT hu'.
> Thanks in advance
>
> Ervin Dobler
> Technical University of Budapest, Department of Atomic Physics.
>
--
Chris Christoph P. U. Kukulies kuku AT gil DOT physik DOT rwth-aachen DOT de
- Raw text -