AnsweredAssumed Answered

Problem with Static variable assignment

Question asked by PRATIBHA SURABHI on Aug 9, 2017
Latest reply on Aug 11, 2017 by ZhangJennie

I am using S12ZVMC128 MCU and Using Codewarrior version 10.7 as IDE.

There are three variables and all are global static variables, If we assign them with Zero at the beggining, They behave randomly and we assign them with the values other than Zero or don't assign them then their behavior will be as expected.

For ex, If

Case 1,

                  static Unsigned char a = 0;            //

                  static Unsigned int b = 0;                // Behavior will be random.  

                  static Unsigned char c = 0;            //

            If

Case 2,

                  static Unsigned char a = 1;             //

                  static Unsigned int b = 1 ;            // Behavior will be fine.  

                  static Unsigned char c = 1;             //

 

            If

Case 3,

                  static Unsigned char a;                   //

                  static Unsigned int b;                    // Behavior will be fine.  

                  static Unsigned char c;                  //

 

Our observation: 

   In Case 1, Case 2 and Case 3, Variables are stored at different locations.

In Case 2, we are guessing that it will be store in initialized data area.

in Case 1 and 3, it will go into .bss, we guess that is happening but still it getting stored in a different in .bss area itself.

 

Note: If it helps you to help in solving this, These variables are used in interrupt ISR routine.

Outcomes