Fortran Coder

查看: 11591|回复: 3
打印 上一主题 下一主题

[求助] 程序报错Interface mismatch in global procedure

[复制链接]

22

帖子

6

主题

0

精华

入门

StarkLee

F 币
96 元
贡献
52 点
跳转到指定楼层
楼主
发表于 2014-12-4 22:54:21 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 306908677 于 2014-12-7 20:55 编辑

不知道这是什么错误诶
[mw_shl_code=fortran,true]  program main
  implicit none
   interface
        subroutine random_arr(a)
        implicit none
        integer(4),intent(out)::a(:)
        end
   end interface
   integer , allocatable :: A(:)
   integer , allocatable :: B(:)
call random_arr(A)
call random_arr(B)
print *,A
print *,B
  end program

subroutine random_arr(a)
                      1
警告: Interface mismatch in global procedure 'random_arr' at (1): ALLOCATABLE mismatch in argument 'a'
/Users/StarkLee/Desktop/EQU.F90:4.22:

subroutine random_arr(a)
                      1
警告: Interface mismatch in global procedure 'random_arr' at (1): ALLOCATABLE mismatch in argument 'a'
Jarvis:~ StarkLee$

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

60

帖子

17

主题

0

精华

专家

F 币
454 元
贡献
266 点
沙发
发表于 2014-12-5 08:24:49 | 只看该作者
本帖最后由 Villain 于 2014-12-5 08:26 编辑

无法重现你的错误,修改了下面的部分,可以build了。可能是你用的是gfortran吧。

[Fortran] 纯文本查看 复制代码
   integer(4), allocatable :: A(:)
   integer(4), allocatable :: B(:)

1963

帖子

12

主题

5

精华

论坛跑堂

臭石头雪球

F 币
1357 元
贡献
574 点

美女勋章热心勋章星光勋章新人勋章贡献勋章管理勋章帅哥勋章爱心勋章规矩勋章元老勋章水王勋章

板凳
发表于 2014-12-5 08:31:36 | 只看该作者
第 6 行改为
[Fortran] 纯文本查看 复制代码
integer(4),intent(out),allocatable::a(:)

就可以了。

另外,不建议传递未分配的可分配数组。

根据经验,这样的做法不容易出错:谁定义,谁分配,谁释放。所以,主程序中定义的数组,就在主程序分配,并在主程序释放。

22

帖子

6

主题

0

精华

入门

StarkLee

F 币
96 元
贡献
52 点
地板
 楼主| 发表于 2014-12-5 13:49:03 | 只看该作者
明白啦,非常感谢
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

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

GMT+8, 2024-5-6 08:39

Powered by Tencent X3.4

© 2013-2024 Tencent

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