Fortran Coder

查看: 10662|回复: 5
打印 上一主题 下一主题

[混编] Fortran与C混编的接口问题

[复制链接]

62

帖子

14

主题

0

精华

专家

F 币
557 元
贡献
326 点
跳转到指定楼层
楼主
发表于 2017-8-31 15:13:18 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 安靖 于 2017-9-1 10:10 编辑

[Fortran] 纯文本查看 复制代码
 Interface
         Subroutine ALLC (pmem,size,message)
!DEC$ Attributes C, Alias : '_allc' :: ALLC
         integer pmem [reference]
         Integer size [reference]
         character(*) message [reference]
         end subroutine ALLCend interface


[C] 纯文本查看 复制代码
/* Function allc */
/* This function allcs memory for 'mem' of size 'size' */
/* In case of failure it outputs a message 'message' */

void allc (int **mem , int *size, char message[200])

{
if (*size < 0)
{
printf (" allc - STORAGE ALLOCATION FAILED: %s \n", message);
printf (" Number of words requested: %d\n", *size);
printf (" Length is <= 0\n");
exit (1);
}
*mem = (int *) calloc (((*size)+1) * sizeof (int),1);
if (*mem == 0)
{
printf (" allc - STORAGE ALLOCATION FAILED: %s \n", message);
printf (" Number of words requested: %d\n", *size);
exit (1);
}
}


以上是一段Fortran与C混编,Fortran调用C来分配内存的接口,以及C的实现

问题1:
integer pmem [reference] 中 [reference] 什么意思? 没见过这种用法

问题2:
按照这种接口,32位的情况下没有问题,但是64位的时候会出现链接错误。
error LNK2001: 无法解析的外部符号 _allc




分享到:  微信微信
收藏收藏 点赞点赞 点踩点踩

62

帖子

14

主题

0

精华

专家

F 币
557 元
贡献
326 点
沙发
 楼主| 发表于 2017-9-1 10:19:41 | 显示全部楼层
本帖最后由 安靖 于 2017-9-1 10:21 编辑
pasuka 发表于 2017-9-1 09:29
网上找了找,原来是VC6时代fortran与C混合编程的遗迹
C/C++ and Fortran Defaults for Passing Parameters
...

感谢解答了我的疑惑,也验证了2楼的猜测。 谢谢2位。

另外,引起第二个问题的原因是 32位和64位下编译出来的函数修饰名(Decoration name)是不同的。
原来一直不知道还有这区别呢
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2024-5-4 01:26

Powered by Tencent X3.4

© 2013-2024 Tencent

快速回复 返回顶部 返回列表