我认为头衔说我需要什么.我知道我们可以使用"asd"函数来执行此操作,但由于某些原因,我需要在Fortran中进行分配(即在子例程"asd_"中).这是C代码:
#include <stdio.h>
void asd(float **c) {
*c = (float *) malloc (2*sizeof(float));
**c =123;
*(*c+1)=1234;
}
void asd_(float **c);
main () {
float *c;
asd_(&c);
// asd(&c); would do the job perfectly
printf("%f %f \n",c[0],c[1]);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这是Fortran代码:
subroutine asd(c)
implicit none
real, pointer, allocatable ::c(:)
print *, associated(c)
if(.not. associated(c)) allocate(c(2))
end subroutine
Run Code Online (Sandbox Code Playgroud)
这随机给出了分段错误.任何帮助,将不胜感激.