Portably:
for ( size_t i = 0; i < 2024; ++i )
spectrum[i].i = spectrum[i].r = 0;
Others have suggested using calloc
or memset
; those will only work if you know you are only coding for a platform that uses a floating point representation in which all-bits-zero means 0.f
, such as IEEE754. (I'm assuming that kiss_fft_scalar
is float
as your title suggests).
If the size is known at compile-time then you can write:
kiss_fft_cpx spectrum[2024] = { 0 };
which will initialize all the values to 0
.
NB. Don't cast malloc and even if size is not known exactly at compile-time but known to be small, you have the option to avoid malloc/free by writing kiss_fft_cpx spectrum[size];
.