Variable is not getting assigned to 0.

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Variable is not getting assigned to 0.

跳至解决方案
974 次查看
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.

标签 (1)
0 项奖励
回复
1 解答
854 次查看
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 项奖励
回复
2 回复数
854 次查看
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 项奖励
回复
855 次查看
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 项奖励
回复