------- Comment #3 from Georg dot Baum at post dot rwth-aachen dot de  
2008-03-30 20:48 -------
Thanks for the quick reply. You where right, I mixed up the FF2C macro in the
test case. Unfortunately this was not the real problem. The problem I had in my
code was that calling BLAS zdotc from C++ did not work. In this case using your
"proper" 2003 way is no option, since the BLAS interface is well defined for
years and won't change. And it is no option either if you use a commercial
Fortran lib where you don't have the source.

After further digging I found out what went wrong, and I'll explain it here in
case somebody else runs into the same problem:
gcc makes a difference between built in types and structs with respect to
function return values (depends on the platform and the
-fpcc-struct-return/-freg-struct-return switches). Therefore the working code
from comment 1 does not work anymore if you replace the C99 complex types with
a struct (even if that struct has the correct memory layout).
This is a pity because many existing C/Fortran interface layers use structs to
exchanging complex data, and this works on many C++/Fortran compiler combos if
you take care of the alignment.
Unfortunately in C++ you can't use C99 complex (it might be possible to use
std::complex, because this is sometimes identical to C99 complex depending on
the compiler config). So if you want to call a Fortran function that returns a
complex number from C++ you have to declare it in a gcc specific way:
double _Complex foo();

(In reply to comment #2)
> > -ff2c: the return value is returned in an additional argument as g77 and 
> > other
> > fortran compilers do it
> 
> I want to point out that all? modern compiler use the -fno-f2c scheme which is
> compatible with the default gfortran output.

Not all. I gave two counter examples: pvf and ifort.

> The f2c syntax goes back to the f2c compiler (www.netlib.org/f2c) which was
> created at a time when C compilers were available but no Fortran 77 compiler
> for free. It translated the Fortran code into C code which had then to be
> compiled. (This is better and more correctly described at
> http://en.wikipedia.org/wiki/F2c)

I know what f2c is. Exactly because I do not want to use the -f2c switch I ran
into the return value problem after switching from g77 to gfortran.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35765

Reply via email to