我有一个非常简单的程序,这让我很困惑。对 c_f_pointer 的调用不起作用,显然我犯了很多错误!
program test
use iso_c_binding
implicit none
interface
subroutine call_fc(size,status) bind(C,name='call_fc_')
import
integer(c_int) :: size
type(c_ptr) :: status
end subroutine
end interface
integer(c_int) :: size=8,i
integer(c_int),pointer :: stat(:)
type(C_ptr) :: statptr
call call_fc(size, statptr)
call c_f_pointer(statptr,stat,(/size/))
print *, 'stat is : ',stat
end program test
和 c++ 子例程是
extern "C" {
void call_fc_(int *size, int *status)
{
int i;
for(i=0; i<*size;i++) {
status[i] = i+10;
printf("%d th value : %d \n", i, status[i]);
}
}
}
当我编译并运行代码时,它会产生以下错误
0 th value : 10
1 th value : 11
2 th value : 12
3 th value : 13
4 th value : 14
5 th value : 15
6 th value : 16
7 th value : 17
Program received signal SIGSEGV: Segmentation fault - invalid memory reference.
谁能告诉我出了什么问题?