一个例子。如果你想要一个返回 void 的函数,你应该使用一个子例程。
function foo(input, output)
implicit none
integer :: foo
integer, intent(in) :: input
integer, intent(out) :: output
output = input + 3
foo = 0
end function
program test
implicit none
integer :: a, b, c, foo
b = 5
a = foo(b, c)
print *,a,b, c
end program
如果您正在调用 C 例程,则签名使用引用。
$ cat test.f90
program test
implicit none
integer :: a, b, c, foo
b = 5
a = foo(b, c)
print *,a,b, c
end program
$ cat foo.c
#include <stdio.h>
int foo_(int *input, int *output) {
printf("I'm a C routine\n");
*output = 3 + *input;
return 0;
}
$ g95 -c test.f90
$ gcc -c foo.c
$ g95 test.o foo.o
$ ./a.out
I'm a C routine
0 5 8
如果你使用字符串,事情就会变得一团糟。