#include
void sub_fortran_(int *,float *,double *);
double function_fortran_(double *);
int main()
{
int num_int;
float num_float;
double num_double;
double num;
num_int=3;
num_float=5.0;
sub_fortran_(&num_int,&num_float,&num_double);
num=function_fortran_(&num_double);
printf("num_int=%d\nnum_float=%f\nnum_double=%f\nnum=%f",num_int,num_float,num_double,num);
return 0;
}
fortran代码:
subroutine Sub_Fortran(NumInt,NumFloat,NumDouble)
implicit none
integer :: NumInt
real :: NumFloat
real(8) :: NumDouble
NumDouble=NumFloat**NumInt
end subroutine
real(8) function Function_Fortran(NumDouble)
implicit none
real(8) :: NumDouble
Function_Fortran=sqrt(NumDouble)
end function
编译:
gcc -o main.o -c main.c
gfortran -o sub.o -c sub.f90
gcc -o main main.o sub.o -lm
运行结果:
$ ./main
num_int=3
num_float=5.000000
num_double=125.000000