variable-sized object may not be initialized, c compilation error, but worked fine with c++
<p>I am trying to convert a c++ script to c. and in my main function I declared an array like the following:</p>

<pre><code>    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 };
}
</code></pre>

<p>I am getting the following error:</p>

<pre><code>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 };
</code></pre>

<p>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:</p>

<pre><code>#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;time.h&gt;
#include &lt;math.h&gt;
</code></pre>

<p>Now I was wondering what might possible go wrong?
I was compiling with:</p>

<pre><code>gcc -o test test_code.c
</code></pre>