|
PROGRAM main IMPLICIT NONE INTEGER i interface subroutine myprint(x) integer, intent(in) :: i end subroutine end interface i = 123 CALL myprint(i) END |
Example:
f90 -S link-1-f90.f90 |
Result: (look for "CALL myprint(i)")
! 15 CALL myprint(i) call myprint_ |
|
#include <stdio.h> void myprint(int *i) { printf("%d", *i); } |
Example:
cc -S link-1-C.c |
Result: (look for "myprint:")
.type myprint,#function myprint: save %sp,-96,%sp ! block 1 .L94: ! File link-1-C.c: ! 1 #include |
|
|
We have a way to invoke a C function from within a F90 program
CC -S link-1-C.c |
See if you can figure out what name in the assembler code is mapped to "myprint()"...
Fortran main program:
PROGRAM main IMPLICIT NONE INTEGER i interface subroutine myprint(x) integer, intent(in) :: i end subroutine end interface i = 123 CALL myprint(i) END |
C function:
#include <stdio.h> void myprint_(int *i) { printf("i = %u", i); printf("*i = %d", *i); } |
Compile using:
cc -c link-2-C.c f90 -c link-1-f90.f90 f90 link-1-f90.o link-2-C.o |
*i |
obtains the parameter passed, Fortran must have passed the parameter by reference
|
The C main program:
void myprint_(int *); int main(int argc, char argv[]) { int i = 1234; myprint_(&i); } |
The Fortran subroutine:
SUBROUTINE myprint(n) IMPLICIT NONE INTEGER, INTENT(IN) :: n print n END SUBROUTINE |
cc -c link-4-C.c f90 -c link-4-f90.f90 f90 link-4-f90.o link-4-C.o |
The answer is NO
Example:
SUBROUTINE myprint(n) IMPLICIT NONE INTEGER, INTENT(IN) :: n n = n + 1 print *, "F90 print integer parameter n = ", n END SUBROUTINE |
Compile with:
f90 -c intent-in.f90 |
You will get a compiler error...