I am trying to convert a c++ script to c. and in my main function I declared an array like the following:
int main(int argc, char **argv)
{
/* define how many integrals */
const int n = 10;
double b[n] = { 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0 };
double a[n] = { -5.0, -5.0, -5.0, -5.0, -5.0, -5.0, -5.0, -5.0, -5.0, -5.0 };
}
I am getting the following error:
test_code.c: In function ‘main’:
test_code.c:73:5: error: variable-sized object may not be initialized
double b[n] = { 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0 };
^
test_code.c:73:21: warning: excess elements in array initializer
double b[n] = { 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0 };
^
test_code.c:73:21: note: (near initialization for ‘b’)
test_code.c:73:26: warning: excess elements in array initializer
double b[n] = { 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0 };
^
test_code.c:73:26: note: (near initialization for ‘b’)
test_code.c:73:31: warning: excess elements in array initializer
double b[n] = { 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0 };
and a lot of lines with the same error. This code was initially written for a c++ script and worked fine with no compilation error at all. I have the following libraries included:
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
Now I was wondering what might possible go wrong? I was compiling with:
gcc -o test test_code.c