- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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:
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
"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
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page