开发者

Passing a derived type from Fortran to C++

I have an old Fortran77 program that calls a C++ function and passes several arra开发者_Go百科ys of values to it (~ 100 individual values total). I'd like to convert the arrays to derived types, to make the code more readable and give names to the individual members of the arrays.

Is it possible to pass a derived type from Fortran to a C++ function?

How does C++ know how the structure looks like? Do I have to define the structure twice (once in Fortran and once in C++), and if yes, is there any automatic way to check that both structures are in sync?

I'm using GCC; I'd obviously have to switch the Fortran code to Fortran95 or higher.


Look into ISO_C_BINDING, the C-Fortran binding that is part of F2003. You can create a derived type with a BIND(C) attribute, which will be compatible with a C struct of the "companion C processor" (in the case of gfortran, gcc).

See chapter 7 in the gfortran manual: http://gcc.gnu.org/onlinedocs/gfortran/Mixed-Language-Programming.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜