Hi everybody I'm trying to adopt the new interface in FFTW3 (it's 3.1 now) to my routine written in C++ (I am using VC++ 7.0) I have used earlier versions of FFTW in C programs, and everything was fine. The problem with the new interface is fftw_complex appears to be totally incompatible with complex<T> template class, infact it seems incompatible with anything and I am unable to cast anything on it. I would understand, if fftw_complex occured to be a vector (double[2]) or a struct, but it's apparently not. The IntelliSense feature of VC++ shows that fftw_complex is equivalent to just a single double type (???), yet the compiler does not allow to substitute a double value to a variable of that type. I am really confused, and have no idea what is going on. a code snippet: #include <complex> #include <fftw3.h> using namespace std; ... complex<double> a = (2.0,3.0); fftw_complex test; test = (fftw_complex)a; generates a compiler error: error C2440: 'type cast' : cannot convert from 'std::complex<double>' to 'fftw_complex' No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called the FFTW3 manual advises to use: reinterpret_cast<fftw_complex*>( complex<double> variable ) due to temporal incompatibility between complex type in C and the complex class in C++ but it still doesn't work! I am getting the same errors over and over again help! MB
fftw_complex cast problem
Started by ●March 22, 2005
Reply by ●March 24, 20052005-03-24
MB wrote:> the FFTW3 manual advises to use: > reinterpret_cast<fftw_complex*>( complex<double> variable )No, it doesn't. It advises using that reinterpret_cast for a complex<double>* variable, not a complex<double> variable. There is a big difference. The reason you are having problems is that, since fftw_complex in FFTW3 is an array double[2] (which was chosen to force it to be binary compatible with the C99 complex types and with C++ complex types), you cannot simply use a=b assignments for fftw_complex variables a and b. C (and C++) don't allow assignments of whole arrays, except in the sense of pointers. Something that should work is listed below. Cordially, Steven G. Johnson PS. Followups should go to comp.lang.c++, since this is a C++ question, not a DSP question. #include <complex> #include <stdio.h> #include <fftw3.h> using namespace std; int main(void) { complex<double> a(2.0,3.0); fftw_complex *test; test = reinterpret_cast<fftw_complex*>(&a); printf("a = %g%+gi\n", real(a), imag(a)); printf("test = %g%+gi\n", test[0][0], test[0][1]); return 0; }
Reply by ●March 24, 20052005-03-24