I must pass complex data to a C function from C++. In C++ the data is naturally stored in a
std::vector<std::complex> c
. The C function expects the data as an array of double, double a[]
such that a[0]=Re(c[0]), a[1]=Im(c[0]), a[2]=Re(c[1]), etc.
What is the best safe way to pass such data? Is casting like
(double*) (&c[0])
asking for trouble?
Sorry if this is duplicate, I could only find information on the related problem of passing C++ complex to C99 complex.