Page 1 of 1

complex16* type in C++

PostPosted: Sat Oct 22, 2005 12:07 pm
by cheng70

I'm calling LAPACK/BLAS from C++ and was wondering what the complex16* type is in C++. I guess it is a built in type of Fortran, which consists of two Real-8 types.
From various examples on the web, it seems like it is just a double type or twice the size:
complex16* = double with double[0]=real part, double[1]=imaginary part. I have all
the other routines working because a double is obviously just a double in C++.

For example, the function zdotu_(int *N, complex16* X, int *incx, complex16* Y, int *incy),
[which takes the dot product of time complex numbers]
is supposed to return a type 'Complex16*', which I guess is a type in Fortran.
Does anybody know what this type is in C++? Is it a structure with 2 double pointers
with names 're' and 'im' or is it just a double[2]. From here, I would really like to know how to store the value of zdotu_. Do you write something like:
double *z;
z=zdotu_(..); ?

Gratefully appreciative for your time,

PostPosted: Mon Oct 24, 2005 11:07 am
by Julie

The double complex does not exist in C or C++ and thus is defined by a structure with 2 double pointers.
Code: Select all
 struct doublecomplex
{   double re;
   double im;

Unfortunately, returning composite objects that occupy more than a single register, or an adjacent register pair, is fraught with peril. Older C and C++ compilers did not support this at all, and newer ones may do it differently than Fortran compilers do: thus, you should not expect to use Fortran functions that return types such as COMPLEX or COMPLEX*16. Write a SUBROUTINE interface to your Fortran function instead, and then invoke it as a void function from C or C++.
For example:
Code: Select all
/* Double Complex */ VOID zdotu_(doublecomplex * ret_val, integer *n,
   doublecomplex *zx, integer *incx, doublecomplex *zy, integer *incy)

Julie Langou