Which compiler are you using? AVR-GCC compiles and runs your code
correctly.
I'll state this again just for the benefit of all those who assume they
can't use GCC because it is too difficult: Studio 4 with the GCC plug in
makes is brain dead simple: Just create a project, cut the code from the
email and paste into the initial file, and press the compile button. Start
debugging, and see that it works.
If you set the compile options for anything other than -oO (default, no
optimization) the compiler correctly identifies the problems and warns you.
GCC is the best and only free compiler!
-----Original Message-----
From: AVR-Chat@yahoogroups.com [mailto:AVR-Chat@yahoogroups.com] On Behalf
Of luthjej
Sent: Sunday, January 28, 2007 5:00 AM
To: AVR-Chat@yahoogroups.com
Subject: [AVR-Chat] Re: C Code weird behaviour help?
Thanks for the reply, Dave
Unfortunately the code snippet below is not the "real" code, but a
quick throw-together to illustrate the problem I'm having.
In the real code, the variables are initialized with real data.
Either statically (for testing) or dynamically from a pre-defined
location in EEPROM.
ICC actually initializes the value to 0 automatically as part of the
compile process anyhow ...
I'm still having no luck trying to solve this problem - might try and
use a series of if-then-else handlers instead of the alternating
while loops ... hmmm ...
Thanks again for the reply.
Cheers,
Jon
--- In AVR-Chat@yahoogroups.com, "Dave Hylands" <dhylands@...> wrote:
>
> Hi,
>
> > Code that doesn't work:
> >
> > main ()
> > {
> > unsigned int val;
> > unsigned int otherval;
> >
> > val = 650;
> >
> > while (1)
> > {
> > while (otherval < val)
>
> otherval is currently uninitialized and will take on some random
value
> from the stack.
>
> > Code that DOES work:
> >
> > main ()
> > {
> > unsigned int otherval;
> >
> > while (1)
> > {
> > while (otherval < 650)
>
> otherval is still uninitialized. The fact that it works is pure luck
>
> --
> Dave Hylands
> Vancouver, BC, Canada
> http://www.DaveHylands.com/
>
Yahoo! Groups LinksMessage
RE: [AVR-Chat] Re: C Code weird behaviour help?
2007-01-28 by larry barello
Attachments
- No local attachments were found for this message.