Loops not executed...

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,
I have a problem with a for- loop in the main Program. The loop is an endless for (;;) loop. In the first line is an "if" statement, the loop looks like this:

void main (void) {

... //init stuff

for (;;) {

if (COM_LEN==4) {
outp(255,UDR);
Sel++;
...}
}
}

This loop will never be executed... I think the compiler removes it... possible?
If I add an "outp(~Led, PORTB)" before the "if" statement, the loop will be executed an all works fine...
Can anyone help me? Its possible, that the Compiler removes this loop? How can I prev. this?

Thanks,
Hanns Tappeiner

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, I've seen it do that before :) What optimization level are you using?
I've found that -O1 is the most reliable and seems to produce the smallest code as well.

Take care,
Mike H.

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I use -O2. I use the gcc paramteres from the gcctest programms, because I doen't know exactly what the different parameters do.
What 's the difference between -O1, -O2 and -O3?

Greetings,
Hanns

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Take a look at the MAN pages. They explain fairly well what each level does.

Each level trys to be a little more aggressive in increasing speed and reducing code size. The man pages will explain it in a little more detail.

Mike H.

admin's test signature