Home > Archive > Fortran > February 2005 > Fortran-90 Object code standard - linking with C ?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Fortran-90 Object code standard - linking with C ?
|
|
| M. Oliver Moeller 2005-02-01, 8:58 pm |
|
Greetings honorable elders.
I want to link mixed language executables from Fortran-90 object code and
standard C, including C-style libraries (libXXX.a).
Of particular interest to me is the Intel Fortran Compiler 8.1, together with
gcc 3.3.1.
I did some experiments like calling f (Fortran) from main (c) and then g (c)
from f, where g was compiled into a C library.
It seems to work, but the parameter passing is still shaky-shaky to me:
Most, but not all parameters seem to be INT32*.
Plus, it matters whether I switch on Fortran output (to stdout, I think) or
not.
I do know only little about Fortran (90) and am new to the Intel Fortran
Compiler 8.1.
Does anybody have
- pointers to documentation of generated Object code
or a standard it complies to?
- hints about compile switches that are useful for this?
- warnings about conceptual problems/limits in passing parameters back and
forth?
Thank you for your time,
- oli http://www.verify-it.de
*com-pu-ter*: device to enhance our capability to err. <omoeller@verify-it.de>
| |
| E. Robert Tisdale 2005-02-01, 8:58 pm |
| M. Oliver Moeller wrote:
> I want to link mixed language executables
> from Fortran-90 object code and standard C
> including C-style libraries (libXXX.a).
> Of particular interest to me
> is the Intel Fortran Compiler 8.1, together with gcc 3.3.1.
>
> I did some experiments like calling f (Fortran) from main (c)
> and then g (c) from f, where g was compiled into a C library.
> It seems to work, but the parameter passing is still shaky-shaky to me:
> Most, but not all parameters seem to be INT32*.
> Plus, it matters whether I switch on Fortran output (to stdout, I think) or
> not.
>
> I do know only little about Fortran (90)
> and am new to the Intel Fortran Compiler 8.1.
> Does anybody have
> - pointers to documentation of generated Object code
> or a standard it complies to?
> - hints about compile switches that are useful for this?
> - warnings about conceptual problems/limits
> in passing parameters back and forth?
Please find attached a couple of header files
that should help you call Fortran 77/90/95/03 from C.
The f77_adapter.h header file maps Fortran 77 intrinsic types
to C99 built-in types *for your compiler*.
/*
* All Fortran 77 type names are of the form:
*
* f77_<type>
*
* where
*
* <type> in {subroutine, character, integer<size>,
* logical<size>, real_4, real_8,
* single, double, offset, length} and
* <size> in {, _1, _2, _4}.
*
* Note that the <size> parameter includes the empty string.
*/
typedef void f77_subroutine;
typedef char f77_character;
typedef int8_t f77_integer_1;
typedef int16_t f77_integer_2;
typedef int32_t f77_integer_4;
typedef f77_integer_4 f77_integer;
typedef uint8_t f77_logical_1;
typedef uint16_t f77_logical_2;
typedef uint32_t f77_logical_4;
typedef f77_logical_4 f77_logical;
typedef float f77_real_4;
typedef double f77_real_8;
typedef f77_real_4 f77_real;
typedef f77_real_4 f77_single;
typedef f77_real_8 f77_double;
typedef int f77_offset;
typedef size_t f77_length;
For example, to call
subroutine f(i)
integer i
you would invoke
f77_subroutine f_(f77_integer*);
in your C program.
The f90_adapter.h header file includes the f77_adapter header file
and allows you to define C structs which contain Fortran 90 pointers
and pass them to Fortran 90/95/03 subprograms.
| |
| Greg Lindahl 2005-02-01, 8:58 pm |
| In article <87y8e74dwh.fsf@gaia.verify-it.de>,
M. Oliver Moeller <omoeller@verify-it.de> wrote:
>It seems to work, but the parameter passing is still shaky-shaky to me:
>Most, but not all parameters seem to be INT32*.
On Linux, the Intel compiler follows the usual Unix traditions:
* everything passed by reference
* character vars are a "char *" with an int length tacked onto the end of the arg list
* F90-style arrays are going to have a dope vector
Plus the f2c perversions:
return value of REAL*4 promoted to REAL*8
COMPLEX return values cause a pointer to get inserted at the start of the arg list
Pretty much all Linux fortran compilers do all this, except that on
x86_64 PathScale doesn't follow the f2c perversions unless you give a
flag, g95/gfortran don't follow it either, PGI follows half of it, and
Intel and g77 do all of it the f2c way.
And, someday, we'll all use the F2003 Fortran-to-C compatibility stuff.
-- greg
[ working for, not speaking for, PathScale. ]
|
|
|
|
|