Problem with Static variable assignment

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problem with Static variable assignment

600 Views
pratibhasurabhi
Contributor V

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.

0 Kudos
1 Reply

398 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi PRATIBHA,

I tried but I couldn't reproduce your problem. Please make a demo project and send it here. I will check it directly.

Thanks!


Have a great day,
Jennie Zhang

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos