1

I am using fftw for a fourier transform in c++. There is the standard data type fftw_complex, which is basically a double[2]. I want to make an array of fftw_complex. I do this with

typedef fftw_complex fftw_complex_16[65536];

I set everything to zero in the array. Then I have another function which should check if an fftw_complex_16 is empty.

bool is_empty_fftw_complex_16(fftw_complex_16 *thecomplex){
    std::cout<<"Test\n"<<::vowels["a:"][0][0]<<std::endl;

    for (unsigned long i=0; i<65536; i++){
         if(thecomplex[i][0] != 0 || thecomplex[i][1] != 0){
            std::cout<<"Huch!"<<i<<std::endl;
            std::cout<<thecomplex[i][0]<<" -- "<<thecomplex[i][1]<<std::endl;
            std::cout<<*thecomplex[i][0]<<" -- "<<*thecomplex[i][1]<<std::endl;

            return 1;
        }
    }
    return 0;
}

Forget about the couts, they are only for debugging. The only thing the function should do is return true if the array the pointer argument points to is empty and false otherwise. It does not work. The function says the array is not empty when it is! Please help, what am I doing wrong?

Tom Atix
  • 381
  • 1
  • 21
  • _"There is the standard data type `fftw_complex`, which is basically a `double[2]`"_ That's no c++ standard data type. – πάντα ῥεῖ Apr 07 '19 at 20:09
  • _"It does not work. The function says the array is not empty when it is! Please help, what am I doing wrong?"_ Provide a [mcve] reproducing your problem as required here please. – πάντα ῥεῖ Apr 07 '19 at 20:11

1 Answers1

3

The problem seems to be this

bool is_empty_fftw_complex_16(fftw_complex_16 *thecomplex){

which from your description should really be this

bool is_empty_fftw_complex_16(fftw_complex *thecomplex){

but it's hard to be completely sure because you didn't post the code which sets up this array and calls this function, which unfortunately is a crucial thing to miss out.

Something like this would be the correct way to call the function

fftw_complex_16 array;
...
is_empty_fftw_complex_16(array);

I'm guessing that you combined the incorrect declaration above with this incorrect call.

fftw_complex_16 array;
...
is_empty_fftw_complex_16(&array);

This compiles but doesn't do what you wanted.

john
  • 85,011
  • 4
  • 57
  • 81
  • It works as expected. But could you explain why I have to use fftw_complex as argument variable type, instead of fftw_complex_16, as the variable given(array) is of type fftw_complex_16? thanks – Tom Atix Apr 08 '19 at 22:14
  • 1
    @TomAtix It's just the normal procedure for C++ when passing an array to a function. As you can't actually pass an array to a function you instead pass a pointer to the first element. In your case each element is a `fftw_complex` so a pointer to the first element is `fftw_complex*`. – john Apr 09 '19 at 06:44
  • Thanks. I understand now. – Tom Atix Apr 09 '19 at 15:52