我是编程新手,我想在我的 C++ 代码中调用 Fortran 77 通用块。其实我读过一些和我类似的问答,但我不是很清楚....
这个公共块由另一个 Fortran 77 子例程定义。
示例代码是:
common.inc:
!test common block:
real delta(5,5)
common /test/ delta
!save /test/ delta ! any differences if I comment this line?
tstfunc.f
subroutine tstfunc()
implicit none
include 'common.inc'
integer i,j
do i = 1, 5
do j = 1, 5
delta(i,j)=2
if(i.ne.j) delta(i,j)=0
write (*,*) delta(i,j)
end do
end do
end
tst01.cpp
#include <iostream>
extern "C"
{
void tstfunc_();
};
void printmtrx(float (&a)[5][5]){
for(int i=0;i<5;i++){
for(int j=0;j<5;j++){
std::cout<<a[j][i]<<'\t';
a[j][i]+=2;
}
std::cout<<std::endl;
}
}
int main()
{
//start...
tstfunc_();
printmtrx(delta);//here i want to call delta and manipulate it.
return 0;
}
如果我想将delta
(从 common.inc)传递给 C++ 函数printmtrx()
,我该怎么办?