Problem with Static variable assignment

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Problem with Static variable assignment

1,102件の閲覧回数
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 件の賞賛
返信
1 返信

900件の閲覧回数
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 件の賞賛
返信