使用C ++的可选参数调用Fortran子例程 [英] Calling Fortran subroutines with optional arguments from C++
问题描述
我如何在使用可选参数的C ++头文件中引用Fortran函数?我会在头文件中为每个可能的呼叫组合添加一个原型吗?或者,这甚至有可能?
例如,Fortran:
子程序foo(a,b,c)绑定(c)
真实,意图(in),可选项:: a,b,c
...
结束子程序foo
除非您使子程序 bind(C)
。
一旦你使它成为 bind(C)
,它只是传递了一个指针,它可以在C端为NULL。
子程序foo(a,b ,c)bind(C,name =foo)
real,intent(in),optional :: a,b,c
...
end子程序foo
(为了更大的可移植性 real(c_float)
来自 iso_c_binding
模块应该被使用,但是这与这个问题有点相似)
在C(++)中
externC{
void foo(float * a,float * b,float * c);
}
foo(& local_a,NULL,NULL);
然后您可以创建一个调用 Fortran允许Fortran在技术规范ISO / IEC TS 29113:2012中进一步实现Fortran与C的互操作性。 How would I reference a Fortran function in a C++ header that uses optional arguments? Would I have a prototype in the header for each possible combination of calls? Or is this even possible? For instance, Fortran:
It is not possible, at least portably, unless you make the subroutine Once you make it (for greater portability In C(++) and then you can make a C++ function which calls This capability was allowed in Fortran in Technical Specification ISO/IEC TS 29113:2012 on further interoperability of Fortran with C. 这篇关于使用C ++的可选参数调用Fortran子例程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! foo $ c的C ++函数
subroutine foo(a, b, c) bind(c)
real, intent(in), optional :: a, b, c
...
end subroutine foo
bind(C)
.bind(C)
, it is just passing of a pointer which can be NULL on the C side.subroutine foo(a, b, c) bind(C, name="foo")
real, intent(in), optional :: a, b, c
...
end subroutine foo
real(c_float)
from the iso_c_binding
module should be used, but that is somewhat tangential to this question)extern "C"{
void foo(float *a, float *b, float *c);
}
foo(&local_a, NULL, NULL);
foo
and which employs C++-style optional parameters.