苏坡,man 发表于 2016-3-31 20:55:05

Program received signal SIGSEGV, Segmentation fault.

下面错误是fortran代码出现的,我主要是想通过c_loc获得p地址,给c数组然后传递给c函数调用。
Program received signal SIGSEGV, Segmentation fault.
0x0000000000408e96 in calc1_neighbor1 (neighbor_addrs=..., args=...) at dag_swim.f:289
289                c_array(num)=c_loc(p(ii-iblock,jj))   
在这行出现段错误,p数组是real类型全局数组。type(c_ptr),pointer::c_array(:)。当ii=2,iblock=1,jj=1,就会出现断错误。
是不是获得地址不对造成的呐?请大神们帮忙



楚香饭 发表于 2016-3-31 22:02:26

我写了个小代码测试,是没有问题的。
Program www_fcode_cn
use , intrinsic :: ISO_C_Binding
Implicit None
Real , target :: p( 3 , 3 )
integer :: ii=2 , iblock=1 , jj=1 , num=3
type(c_ptr),pointer::c_array(:)
Allocate( c_array(5))
c_array(num)=c_loc(p(ii-iblock,jj))   
write(*,*) 'OK'
End Program www_fcode_cn
你再其他地方找找原因吧。
页: [1]
查看完整版本: Program received signal SIGSEGV, Segmentation fault.