c-fortran interoperability - derived types with pointers

依然范特西╮ 提交于 2019-12-06 07:57:08

Not really. Even the brand new TS 29113 does not offer a solution. It has the TYPE(*) but you have to know, how to decode the structure in C. You can do it by reverse engineering.

There is actually a macro for the size of the structure in the referenced TS. See CFI_attribute_allocatable. But the problem with dereferencing remains. There is a standard array descriptor proposed, but this TS is not yet supported by some compilers (notably by gfortran).

What is possible, is to just pass the pointer to the structure to a generic function such as qsort. Then you use just a piece of memory, that happens to contain also some pointer or allocatable descriptor, but C does not have to know about them.

Another possibility is to construct a derived type which holds only type(c_ptr), instead of Fortran pointers and use c_loc() to fill them. Be sure to have only contiguous arrays then.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!