0

my code have this error when compiling in Dev-C++.

The error is: [Error] initializer-string for array of chars is too long [-fpermissive]

And part of code is:

struct ffthdr {
char fftc[4];     // .fft
long fftsize;     // fft size
long windowsize;  // windowsize (<= fftsize)
long hopsize;     // hop size (<=fftsize) 
long dlength;     // original file data length in samples
long srate;       // original file sample rate 
long winType;       // window type 
};

void rfft(float *x, long N, int forward);
void cfft(float *x, long NC, int forward);
void bitreverse(float *x, long N);
int makewindow(int aType, float *win, long length);
int dowindow(float *fdata, float *window, long length);

int main(int argc, char *argv[])   {
float *result,*tempres=0,*window=0;
short *data;
float max,norm=1.0;
long i,time,fsize=1024,wsize=512,hsize=256,nread;
int wavein;
long length,srate,winType=1;
FILE *input, *output;
struct soundhdr hdr;
struct ffthdr fhdr =  {".fft",1024,512,256,0,0,1};

The erros appears on the last line.

Thanks.

Jose Carlos
  • 3
  • 1
  • 2

1 Answers1

2

It's because the initializer-string for your array of chars is too long

This

".fft"

is 5 characters long (including the NUL)

You've only allocated 4:

char fftc[4];     // .fft

If you really want those four characters and no NUL, try

struct ffthdr fhdr =  {{'.','f','f','t'},1024,512,256,0,0,1};
The Archetypal Paul
  • 41,321
  • 20
  • 104
  • 134
  • 1
    From ANSI C 6.5.7: *Successive characters of the character string literal (including the terminating null character **if there is room** or if the array is of unknown size) initialize the elements of the array.* So why is the compiler ignoring the standard? Yes, I saw this was a C++ compiler. – SPC Nov 10 '18 at 13:54
  • It's not "ignoring the standard". Quite the reverse. It's choosing to make errors some things the standard leaves as permissible, because it's very likely to be a coding error, despite what the standard says. Note the "-fpermissive", and see this question: https://stackoverflow.com/questions/8843818/what-does-the-fpermissive-flag-do. So the "answer" does answer the question as it correctly says why that code gets an error from that compiler. – The Archetypal Paul Nov 11 '18 at 17:46