cancel
Showing results for 
Search instead for 
Did you mean: 

STM array not being initialized properly.

SMehr.2
Associate

I want to run some C++ code on my STM32H747I-DISCO board. I am trying to initialize 4D vector with all values as 6. (just for initialization purposes). The shape of the vector is (1,23,249,4). I have two variables s1 and v1, which store the size and the first value of the array. That is, I run this code:

vector<vector<vector<vector<float>>>> output_1(1, vector<vector<vector<float>>>(23, vector<vector<float>>(249, vector<float>(4, 6.0))));
    int s1 = output_1.size();
    int v1 = output_1[0][0][0][0];

  

Obviously, the values of s1 and v1 should be 1 and 6. But looking at the live expression counter, the values are coming out to be 0,0. The size of 0 means the vector isn't initialized properly. Why is this happening? Infact, when I create a new variable int v2 = v1+1; the value of v2 is also shown as 0.

I am using live expression because I'm unable to use printf properly. Also, the optimization for the compiler is O0. The live expression counter is giving correct values for my other variables but somehow is giving a weird result for these 3 lines. Please help me out with this, it's urgent.

 EDIT: I realized something. I have a few lines of code above these 3 lines as well. When, I move those below these 3 lines, I get s1 and v1 correctly but I then the variables whose values were earlier displayed properly, are now being shown as 0.

1 REPLY 1
S.Ma
Principal

Most MCU are C programmed. C++ used by mBed or Arduino will use then different compilers which C++ specifics will also use dedicated libraries. Matrix math being one of them. Beware function local variables big in memory footprint will probably be put in stack which size may need to be increased. Also when testing, avoid compiler optimisations, for example tag them volatile.