Mail Archives: djgpp/1997/10/01/12:46:57
[Posted and mailed]
In article <343147a1 DOT 399544 AT news DOT uni-siegen DOT de>,
kretlow AT hrz DOT uni-siegen DOT d400 DOT de (Mike Kretlow) writes:
> Hi,
>
> possibly my question is a faq, but I didn't found any hint in my docs
> and it is urgent.
>
> I have some f77 subroutines, which I like to call from my c program.
> I compiled the file sub.f with g77 under dos and the main c-program
> with djgpp 2, but the linker couldn't find the subroutines (I declared
> them of course as extern).
There are some things to do:
First a FORTRAN subroutine FOO has to be declared and called by C as
extern void foo_;
foo_(parameters);
(g77-Fortran appends underscores to all subroutine-names)
Second: All parameters are called by reference, i.e.:
SUBROUTINE FOO(A,B,C)
INTEGER*4 A,
REAL*4 B(10) <= Has values B(1),...,B(10)
REAL*8 C(3,4) <= In memory as C(1,1),C(2,1),C(3,1),C(1,2),...,C(3,4)
Has to be called from C:
int a;
float b[10]; <= Fill in values b[0],...,b[9]
double c[4,3]; <= In FORTRAN the leftmost index runs fastest,
so change index-order.
foo_(&a,b,c);
Third: Try to avoid passing character strings to Fortran.
(They are passed by reference, too, but compiler-specific length
information is appended to the parameter list as a long value
at the end of all parameters - there is no 0-termination...)
Hope that helps,
Martin.
- Raw text -