user4308228
user4308228

Reputation:

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

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.

Upvotes: 2

Views: 816

Answers (1)

d_1999
d_1999

Reputation: 854

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.

Upvotes: 1

Related Questions