int n=4;
float A[n][n][n][n];
A[n][n][1][1]=1;
is not valid in every C standard (read n1570 or better). You may want to code const int n=4;
or #define n 4
(on cheap microcontrollers you might not even have enough stack space for 256 floats -> possible stack overflow)
And then, you always have a buffer overflow (read about undefined behavior). In A[x][x][1][1]
the valid indexes are from x
being 0 to x
being 3 -that is n-1
- (not 4).
You might want to code
A[n-1][n-1][1][1] = 1;
but you should know that A[0][0][0][0]
is being uninitialized. It may contain garbage (signalling NaN), and an hypothetical printf("%f\n", A[0][0][0][0]);
could fail ....
I guess that Frama-C would have caught your mistake (I leave you to check that). Be aware of Rice's theorem.
I would initialize A
with zeros (to ease debugging, and to have more reproducible runs) -after having corrected the buffer overflow-:
float A[n][n][n][n]={0.0};