Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Calling Fortran FTNs from C

richardawarren
Beginner
717 Views
I've scanned the "Building Applications" document and found a topic which begs for clarification. The text regarding an application calling FORTRAN from C includes a sentence which reads:
"For the following data types, Fortran adds a hidden first argument to contain function return values: COMPLEX, REAL*16, and CHARACTER"
There's no text to describe how single precision (real*4) values get returned and how that differs or agrees with 'C'. I believe for example, that 'C99' returns a float as a "double" and then demotes that value into the caller single precision "float" variable.

The other point which I'd like to confirm is the 'C' calling function needs to add the 'hidden' return by refererence argument when calling a function returning a 'COMPLEX', etc...?

Many thanks,
Richard



0 Kudos
2 Replies
Steven_L_Intel1
Employee
717 Views
REAL*4 and REAL*8 (and integer) values get returned in registers, so do not take up argument list positions.

I suggest that you check your C compiler documentation to see how it deals with "complex", which I think was added in C99. It may not be treated the same as Fortran COMPLEX as far as functions go. This should be easy to determine with some experimentation.
0 Kudos
TimP
Honored Contributor III
717 Views
ifort doesn't have an option, such as gfortran has, to accept a double value from a C function as a default real. That usage hasn't been common since maintenance of g77 ended, although the 32-bit practice of returning float in the same register as double should make it work the same.
iso_c_binding data types, such as c_float_complex, c_float, seem more appropriate if you are writing new code. c_float_complex matches the C99 float _Complex data type.
Few C compilers have a data type compatible with REAL*16. c_long_double is more often the x87 80-bit format. C99 doesn't specify the implementation of long double; it only requires presence of long double math library, which was optional before.
0 Kudos
Reply