Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

C Code weird behaviour help?

2007-01-27 by luthjej

Hi all,


 I'm hoping someone may be able to offer some assistance to a weird
"C" behavior problem I'm having (ICC v7).

The target platform is a Mega16.

The problem I've simplified below - basically the code below does not
work, the two while loops (outside of the main "infinite" loop) are
supposed to alternate depending on the value assigned to "val"
(greater than or less than 650), however when using the variable
comparison - the loop never finishes (i.e. (otherval < val) is always
TRUE, regardless of the value applied to the "otherval" variable).

Confusingly (for me, at least :) - If I substitute the actual integer
in place of "val" in the while loop test statement - it all works fine.

Thanks in advance for any help ... this one has me stumped!

Cheers,

Jon


Code that doesn't work:

main ()
{ 
  unsigned int val;
  unsigned int otherval;

val = 650;

while (1)
 {
   while (otherval < val)
    {
     otherval++;
    }
   while (otherval >= val)
    { 
     Do_other_stuff();
    }
  }

}

Code that DOES work:

main ()
{ 
  unsigned int otherval;

while (1)
 {
   while (otherval < 650)
    {
     otherval++;
    }

   while (otherval >= 650)
    { 
     Do_other_stuff();
    }

  }

}

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.