怎样在FORTRAN里面调用C写的函数?

moyadao 2004-09-23 11:24:31
怎样在FORTRAN里面调用C写的函数?
哪位大虾能帮帮忙!!
...全文
149 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
moyadao 2004-09-28
  • 打赏
  • 举报
回复
晕,没人回答吗?
lynux 2004-09-28
  • 打赏
  • 举报
回复
好好学习
quain_tchew 2004-09-28
  • 打赏
  • 举报
回复
上面是pgi编译器的, gnu的是一样的写法
quain_tchew 2004-09-28
  • 打赏
  • 举报
回复
10.8 Example - Fortran Calling C
Example 10-4 shows a C function that is called by the Fortran main program shown in Example 10-3. Notice that each argument is defined as a pointer, since Fortran passes by reference. Also notice that the C function name uses all lower-case and a trailing "_".

logical*1 bool1
character letter1
integer*4 numint1, numint2
real numfloat1
double precision numdoub1
integer*2 numshor1
external cfunc
call cfunc (bool1, letter1, numint1, numint2,
& numfloat1, numdoub1, numshor1)
write( *, "(L2, A2, I5, I5, F6.1, F6.1, I5)")
& bool1, letter1, numint1, numint2, numfloat1,
& numdoub1, numshor1
end

Example 10-3: Fortran Main Program fmain.f




#define TRUE 0xff
#define FALSE 0
void
cfunc_( bool1, letter1, numint1, numint2, numfloat1,\
numdoub1, numshor1, len_letter1)
char *bool1, *letter1;
int *numint1, *numint2;
float *numfloat1;
double *numdoub1;
short *numshor1;
int len_letter1;
{
*bool1 = TRUE;
*letter1 = 'v';
*numint1 = 11;
*numint2 = -44;
*numfloat1 = 39.6 ;
*numdoub1 = 39.2 ;
*numshor1 = 981;
}

Example 10-4: C function cfunc_

Compile and execute the program fmain.f with the call to cfunc_ using the following command lines:
$ pgcc -c cfunc.c
$ pgf90 cfunc.o fmain.f

Executing the a.out file should produce the following output:
T v 11 -44 39.6 39.2 981
pacman2000 2004-09-24
  • 打赏
  • 举报
回复
这年头用fortran的太少了。。。
moyadao 2004-09-24
  • 打赏
  • 举报
回复
没人知道吗?
moyadao 2004-09-24
  • 打赏
  • 举报
回复
工程计算还得靠它啊,它在计算上是最好的

23,127

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧