FORTRAN 中子程序的指针
在 FORTRAN 中,如何我可以创建并使用一个指向子例程的指针吗?
此外,是否可以有一个空指针数组指向各个子例程?
我知道这些东西可以很容易地用C实现,但是FORTRAN呢?
编辑
我尝试使用该命令:
PROCEDURE (), POINTER :: pMYSUB => NULL()
我使 pMYSUB 指针指向子例程:
pMYSUB => MYSUB
我还将 MYSUB 子例程放入接口中:
INTERFACE
SUBROUTINE MYSUB
END SUBROUTINE
END INTERFACE
MYSUB 子例程没有参数。问题是,当我使用:
call pMYSUB
我收到链接错误:无法解析的外部符号_pMYSUB。 我做错了什么? 命令:
POINTER(pMYSUB, MYSUB)
是使点 pMYSUB 指向子程序 MYSUB 的另一种方法吗?
Possible Duplicate:
Function pointer arrays in Fortran
How to alias a function name in Fortran
In FORTRAN, how I can create and use a pointer, which points to a subroutine?
Furthermore, is it possible to have a hole array of pointers pointing in various subroutines?
I know that these things can be easily implemented in C, but what about FORTRAN?
EDIT
I have tried to use the command:
PROCEDURE (), POINTER :: pMYSUB => NULL()
I made pMYSUB pointer to point at the subroutine:
pMYSUB => MYSUB
I have also put MYSUB subroutine into INTERFACE:
INTERFACE
SUBROUTINE MYSUB
END SUBROUTINE
END INTERFACE
MYSUB subroutine has no arguments. The problem is that when I use:
call pMYSUB
I get the linking error: unresolved external symbol _pMYSUB.
What I am doing wrong?
The command:
POINTER(pMYSUB, MYSUB)
is another way of making the point pMYSUB to point at the subroutine MYSUB?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Fortran 中的函数指针称为“过程指针”,是 Fortran 2003 标准的一部分。如今许多现代编译器都支持它们。还有一种非常有限的函数指针形式,至少可以追溯到 F77,其中您可以有一个过程参数,它是一个过程;但在 F2003 之前你不能有普通的函数指针变量。如果您在根据上述内容进行谷歌搜索后仍然遇到问题,请发布您正在编写的一些代码,我相信有人会帮助您解决。
沃特。指针数组,由于某种原因不允许。常见的解决方法是创建带有指针组件的派生类型,然后创建这些派生类型的数组。
Function pointers in Fortran are called "procedure pointers", part of the Fortran 2003 standard. Many modern compilers support them nowadays. There's also a very limited form of function pointer going back to at least F77, where you can have a procedure argument which is a procedure; you cannot have normal function pointer variables before F2003 though. If you have problems even after googling up something based on the above, post some code of yours that you're writing and I'm sure someone will help you out.
Wrt. an array of pointers, that is for some reason not allowed. The common work-around is to create a derived type with a pointer component, then make an array of these derived types.
问题是我的子例程的名称是 DO_CALC,并且由于某种原因,该语句:
编译器不喜欢。我更改了子程序的名称,现在可以正常工作了!
@Janneb,使用派生类型数组而不是函数指针数组是个好主意,这在 Fortran 中是不允许的。
The problem was that my subroutine's name was DO_CALC, and for some reason the statement:
didn't like to the compiler. I changed my subroutine's name and now works OK!
@Janneb, nice idea to use an array of derived types instead of an array of function pointers which is isn't allowed in Fortran.