How to prepare a fortran module from a C header file?

爱⌒轻易说出口 提交于 2019-12-10 11:13:57

问题


I have this pure C file with 6 functions that I want to make available for fortran programmers:

http://tinyfiledialogs.sourceforge.net

Could C to Fortran "Import" work ?

Should I simply prepare something like a Fortran header file instead ?

I realise that my C code is using several Unix or Windows C header files, and this will complicate the conversion. But surely offering the equivalent of a Fortran header for 6 C functions must be achievable.

char const * tinyfd_inputBox (
    char const * const aTitle ,
    char const * const aMessage ,
    char const * const aDefaultInput ) ; 
   // the returned value is a static array

edit: I am starting to realize that modules are actually compiler-dependent. Maybe I should instead prepare a makefile that would produce both the C object file and the fortran module to use it.


回答1:


If your aim is to make life easy for fortran programmers and help them to use your C code directly in their program then you probably want to look at generating fortran modules that provide interfaces. These are somewhat similar to your example header in that they define the routine type and the required inputs and outputs.

I'm not particularly experienced in this so I won't give a specific example here but I'll refer you to this site. Another useful source of information would be to look at how other packages do this, for example netcdf and PETSc.



来源:https://stackoverflow.com/questions/37673536/how-to-prepare-a-fortran-module-from-a-c-header-file

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