stretching my (g)fortran legs …

Working on a quick project for a partner. I haven’t done much fortran programming in the last few years, mostly C, Perl, and a few other things.

Its been a while, but now I am remembering why I disliked multi-language programming in the past. You have to fight with the linkers (and compilers) to get them to do the right thing. Stuff that should “just work” doesn’t.

I really, really, just want to


call c_Function(argument1, argument2, ...)

with some c method like this


void * c_Function(...)

Notice that there are no extra “helpful” underscores. And notice that the capitalization of the method is the same.

Really, thats all I want. A nice simple … no … really … simple … interface.

I must be dense, because I don’t quite understand why we can’t get this.

Oh well.

Otherwise, gfortran is quite nice. Looks like some differences between 4.2 and 4.3 … but nothing too painful.

Viewed 7957 times by 1705 viewers

Facebooktwittergoogle_plusredditpinterestlinkedinmail

One thought on “stretching my (g)fortran legs …

  1. First off, your C function is returning a void*, so it would have to be a function in Fortran and not a subroutine. And recent Fortran compilers include F2008’s C interface, which makes the compiler side nicer. You still need all the appropriate run-time libraries, but that’s true regardless of language combination. Objects from two different C compilers also would need two different runtimes in many cases (c.f. visual c++ and mingw).

    A C subroutine void foo(int a, float b) would translate to something like interface; subroutine foo(a, b) bind(C); use, intrinsic:: iso_c_binding; integer(c_int):: a; real(c_float):: b; end subroutine foo; end interface; with newlines for the semicolons. Declaring functions requires declaring the return type after the iso_c_binding import, but it works.

Comments are closed.