Variable is not getting assigned to 0.

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

Variable is not getting assigned to 0.

Jump to solution
860 Views
venkateshgv
Contributor II

We are working on MC9S08QD4 with Code Warrior v6.3. When we assign 0 to a variable it is not getting assigned to 0 and it works with the previous value sometimes. Please share your feedback.

Labels (1)
0 Kudos
Reply
1 Solution
740 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi,

I wonder the problem is because of the optimization.

I suggest you cast the variable as "volatile" then try again. for example.

volatile int myval;


Have a great day,
Jun Zhang

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

View solution in original post

0 Kudos
Reply
2 Replies
740 Views
BlackNight
NXP Employee
NXP Employee

Could you share a reproducible example?

for example, if you have something like:

int i;

i = 10;

i = 0;

i = 20;

then the compiler will be able to optimize this.

0 Kudos
Reply
741 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi,

I wonder the problem is because of the optimization.

I suggest you cast the variable as "volatile" then try again. for example.

volatile int myval;


Have a great day,
Jun Zhang

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

0 Kudos
Reply