cancel
Showing results for 
Search instead for 
Did you mean: 

wrong variable initialisation

Tobias Witte
Associate II
Posted on June 13, 2018 at 09:13

Hello all,

I have a proplem with initialising variables in a function. The function is -with some other functions- in a seperate .c file. Here is a picture with the start of the function.

0690X0000060LAUQA2.png

The variable last_block and the structure state s gets initialised but deflate_type and deflate_error not. I difnied them as static so I can watch them in the live watch view:

0690X0000060LEzQAM.png

The variable ''val'' is in another function in the same file. As you can see the variables val, deflate_type and deflate_err gets all the location 0x00000000 which value is the address of CSTACK$$Limit. The variables last_bloc and deflate_type gets initialised in the same code line (see picture above) but last_block works and deflate_type not. I looked in the map file and I only can´t find the variable last_block and the structure state s. Maybe someone know why the other variables didn´t get initialised correctly?

Regards

Tobias

3 REPLIES 3
AvaTar
Lead
Posted on June 13, 2018 at 09:46

Isn't zero an initialization value ?

I use to initialize all static variables explicitly, even with zero.

And I'm pretty sure with '-Wa' you get a respective warning.

Posted on June 13, 2018 at 09:58

I am not shure what you mean. The location of the variables val, deflate_type and deflate_err is 0x00000000 but the value 0x20000B08. Even when I initialise them with  0 the value is 0x20000B08

Posted on June 13, 2018 at 10:15

The location of the variables val, deflate_type and deflate_err is 0x00000000...

Ahhh yes, correct. Which is strange IMHO, or is 0 a valid address ???

Are you sure the compiler did not optimize it out ?

Try with 'static volatile'.