I have a code which uses the std::complex<double>
type.
From FFTW Manual :
if you have a variable
complex<double> *x
, you can pass it directly to FFTW viareinterpret_cast<fftw_complex*>(x)
.
However, when I do this in my code :
tmp_spectrum = reinterpret_cast<std::complex<double>*>(fftw_alloc_complex(conf.spectrumSize()));
plan_bw_temp = fftw_plan_dft_c2r_1d(conf.FFTSize(), reinterpret_cast<fftw_complex*>(tmp_spectrum), tmp_out, FFTW_ESTIMATE);
I get dereferencing type-punned pointer might break strict-aliasing rules [-Wstrict-aliasing]
.
How to solve this warning ? Thanks !
You have three options here:
fftw_complex
when you need one:fftw_plan_dft_c2r_1d(conf.FFTSize(), fftw_complex(tmp_spectrum.real(), tmp_spectrum.imag()), tmp_out, FFTW_ESTIMATE);
fftw_complex
type.-fno-strict-aliasing
. Silencing just the warning is not safe as it might result in broken code.