CW removes dead code that shouldn't be dead.

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

CW removes dead code that shouldn't be dead.

ソリューションへジャンプ
3,227件の閲覧回数
Smiffytech
Contributor III

Help, help, I'm being repressed! Er, optimised   This is CodeWarrior 10.2, target is HCS08.

 

For some reason, when I follow a loop with another loop, subsequent loops are getting optimised out, with a message "...ProcessorExpert.c:70:warning:C5660 Removed dead code"


Here is a sample of my code:


/* Write your code here */

/* For example: for(;;) { } */

for(;;)

{

  for (i=1; i<=255; i++)

  {

    LED1R_SetRatio8(i); 

    LED2G_SetRatio8(255-i);

    WAIT1_Waitms(5);

  }

  

  for (i=1; i<=255; i++)

  {

    LED2B_SetRatio8(i); 

    LED1R_SetRatio8(255-i);

    WAIT1_Waitms(5);

  }

}


Why am I not able to have subsequent loops?

 

ラベル(1)
タグ(2)
0 件の賞賛
返信
1 解決策
1,791件の閲覧回数
BlackNight
NXP Employee
NXP Employee

Hi Matthew,

Hint: pay close attention to compiler warning and information messages ;-).

I assume your variable 'i' is of type unsigned char?

That means that the variable has a value range of 0..255 (0..0xff).

And if you do a comparison of 'i<=255' in the for() loop, this means that this condition is always TRUE.

As such, you should see a message C4000 Condition always is TRUE (unless you have switched off such messages).

Which means that your first loop never will finish.

:-).

Hope this helps,

Erich

元の投稿で解決策を見る

0 件の賞賛
返信
2 返答(返信)
1,792件の閲覧回数
BlackNight
NXP Employee
NXP Employee

Hi Matthew,

Hint: pay close attention to compiler warning and information messages ;-).

I assume your variable 'i' is of type unsigned char?

That means that the variable has a value range of 0..255 (0..0xff).

And if you do a comparison of 'i<=255' in the for() loop, this means that this condition is always TRUE.

As such, you should see a message C4000 Condition always is TRUE (unless you have switched off such messages).

Which means that your first loop never will finish.

:-).

Hope this helps,

Erich

0 件の賞賛
返信
1,791件の閲覧回数
Smiffytech
Contributor III

Thanks, Erich! I didn't notice any other warnings, but I guess they may have been scrolled off the page.

Now that you point out the error, yes, I can well see what I've done! That's the problem with not being used to typed languages - I've written tens of thousands of lines of Perl over the last few years, but very, very, little C - so it would have taken me a LONG time to spot that, if you hadn't pointed it out!

Whilst I was waiting to see if anyone came up with an answer, I started testing something else - driving the LEDs by setting the PWM values and the delays between changing them from the output of an LFSR, which I generated the code for using lfsr-generator - makes for some very groovy effects! (This project is actually wearable jewellery - LED effects triggered by an MMA7660 accelerometer, for which I am now working on the I2C code.)

Thanks again for your continued support!

0 件の賞賛
返信