Skip to main content
Tobias Witte
Associate II
June 13, 2018
Question

wrong variable initialisation

  • June 13, 2018
  • 1 reply
  • 2171 views
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

    This topic has been closed for replies.

    1 reply

    AvaTar
    Senior III
    June 13, 2018
    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.

    Tobias Witte
    Associate II
    June 13, 2018
    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

    AvaTar
    Senior III
    June 13, 2018
    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'.