Variable is not getting assigned to 0.

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

Variable is not getting assigned to 0.

ソリューションへジャンプ
1,022件の閲覧回数
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 解決策
902件の閲覧回数
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 返答(返信)
902件の閲覧回数
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 件の賞賛
返信
903件の閲覧回数
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 件の賞賛
返信