本帖最后由 安靖 于 2014-12-27 12:45 编辑  
 
在编程工具交流版块中发过类似的帖子  http://bbs.fcode.cn/thread-393-1-1.html 
 
现在在动态内存的传递上遇到了问题。在c++中申请内存空间,传给fortran,但是失败了 
 
 
演示例子 
 
 
c++, testCPP.cpp 
[C++] syntaxhighlighter_viewsource syntaxhighlighter_copycode #indef __cplusplus
extern "C"{
int test_fun_(int *i, int *j, int **array);
}#endif
int test_fun_(int *i,  int *j,  int **array)
{
    int a;
    array= new*[*j];
    for(a = 0; a < *j; a++)
    { 
        array[a] = new int[*i];
    }
    return 0;
} 
 
 
fortran文件 testF.f90 
[Fortran] syntaxhighlighter_viewsource syntaxhighlighter_copycode program main
     implicit none
     integer ::  i, j
     integer, allocatable, dimension(:,:) :: arry
     i = 3
     j = 4
     call test_fun(i, j , arry)
    if(allocated(array))then          write(*,*) 'sucessful!'
    else
         write(*,*) 'fail!'
    end if
end program 
g++  -c  testCPP.cpp 
ar -cr libtest.a testCPP.o 
 
ifort -c testF.f90 
ifort -o test testF.o -L./ -ltest -lstdc++ 
运行./test 
fail 
 
哪里出问题了? 
 
 
 
 
 
 
 
 
 
 
 |