c++ - FFTW : how to prevent breaking aliasing rules? -
i have code uses std::complex<double>
type. fftw manual :
if have variable
complex<double> *x
, can pass directly fftw viareinterpret_cast<fftw_complex*>(x)
.
however, when in 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 dereferencing type-punned pointer might break strict-aliasing rules [-wstrict-aliasing]
. how solve warning ? !
you have 3 options here:
- just create
fftw_complex
when need one:fftw_plan_dft_c2r_1d(conf.fftsize(), fftw_complex(tmp_spectrum.real(), tmp_spectrum.imag()), tmp_out, fftw_estimate);
- don't use c++ language's complex type in code, , use
fftw_complex
type. - disable strict-alias optimizations , enforcement in appropriate translation unit
-fno-strict-aliasing
. silencing warning not safe might result in broken code.
Comments
Post a Comment