还好,fortran的指针还不算太差 - 悲催的科学匠人 - 冷水's blog
还好,fortran的指针还不算太差
冷水
posted @ 2011年11月26日 02:40
in fortran
, 1495 阅读
指针可传给c语言做void*
program test implicit none integer,pointer,dimension(:,:) :: dat, ptr integer, target :: buff(10,10) integer(8) :: n,l,leng,buffsize leng = 100 buffsize = leng*sizeof(buff(1,1)) allocate(dat(1:10,1:10)) leng = 1 do n=1,10 do l=1,10 dat(l,n) = leng leng = leng + 1 enddo enddo leng = 100 ptr => dat call cwrite(ptr, buffsize) ptr => buff call cread(ptr,buffsize) do n=1,10 write(*,'(10I5)') buff(:,n) enddo deallocate(dat) end
#include <stdio.h> void cwrite_(void * buff, long int* len) { long int i; FILE * fp; fp = fopen("test.dat","wb"); fwrite(buff,1,*len,fp); fclose(fp); } void cread_(void * buff, long int* len) { long int i; FILE * fp; fp = fopen("test.dat","rb"); fread(buff,1,*len,fp); fclose(fp); }