Yahoo Groups archive

AVR-Chat

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

Message

RE: [AVR-Chat] C Code weird behaviour help?

2007-01-27 by Cat C

maybe you should be more specific about "int"... like "uint_8t", "uint_16t" 
etc.
I may have gotten the actual names wrong, but U get the idea (I hope).

Good luck.

Cat

----Original Message Follows----
From: "luthjej" <luthjej@yahoo.com.au>
Reply-To: AVR-Chat@yahoogroups.com
To: AVR-Chat@yahoogroups.com
Subject: [AVR-Chat] C Code weird behaviour help?
Date: Sat, 27 Jan 2007 06:24:58 -0000

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();
     }

   }

}




Yahoo! Groups Links



_________________________________________________________________
Buy, Load, Play. The new Sympatico / MSN Music Store works seamlessly with 
Windows Media Player. Just Click PLAY. 
http://musicstore.sympatico.msn.ca/content/viewer.aspx?cid=SMS_Sept192006

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.