This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Interoperability and compiler compatibility


Hi,

Sorry if this is the wrong forum for this question.  I've been asked
to port a large, mixed Fortran/C code base from the Intel compilers on
Windows to the GNU compilers on Linux, maintaining source code
compatibility with both compilers.

The problem I'm facing is that the existing code quite often doesn't
use the ISO_C_BINDING facilities for interoperability (indeed quite a
bit of the code predates ISO_C_BINDING).  Instead, a C function like
this:

    void PRINTSTR(char *str, int len) {
        for(int ii = 0; ii < len; ii++) {
            putchar(str[ii]);
        }
        putchar('\n');
    }

will be called like this:

    program test
    implicit none
        call printstr("Hello, world.")
    end

The Intel build is configured to always emit symbols in upper case, so
the above works; it fails when built with gcc because it always emits
Fortran symbols in lower case but preserves the case of C symbols.

It's been suggested that I could add interface sections with BIND(C,
name='PRINTSTR') for each of these functions.  However, that also
changes the function signature - for instance, no length is provided
for string arguments and string arguments must then be
null-terminated.  So using BIND(C,...) would be a considerable change
to the code base to account for these changed semantics.

There are approximate 240 such functions in the code base, called a
total of about 400 times, so any code change is going to be a fairly
major investment.  I'm hoping there is some compiler option that I
have yet to find that will sort this out for me.  Does it exist?

Barring that, is my best option to modify the Intel-based build to
emit lower-case names and rename all these functions to lower case in
the C code?

Thanks for any assistance,
Tom


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]