avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AW: [avr-gcc-list] An old but unfixed bug


From: Christoph Plattner
Subject: Re: AW: [avr-gcc-list] An old but unfixed bug
Date: Wed, 22 Aug 2001 12:50:06 +0200

This is a normal optimize operation.

To avoid the compiler to optimize such stuff, use "volatile",
here for the varible:

volatile unsigned char x;
volatile unsigned int i;

void main(void)
{
   for(i = 1000; i <= 0xFFFF; i++)
     x = 0;
}

Here the counter must be volatile !!
Setting x to zero will surely be done, but only one time !

A word to 0xFFFF ! If you would use strict warnings, the compiler
would perhaps output a warning, that you compare an UNSIGNED with
a SIGNED, as 0xFFFF is -1 and signed, 0xFFFFu is 65535 and unsigned !

So 1000 is never < -1 !!!

With friendly regards
        Christoph P



> Stumpf Michael wrote:
> 
> >
> > It seems it is not even working with integers ...
> > Look at this code, which i guess loops forever:
> > ----------source-----------
> > volatile unsigned char x;
> > unsigned int i;
> >
> > void main(void)
> > {
> >    for(i = 1000; i <= 0xFFFF; i++)
> >      x = 0;
> > }
> 
> well, i as an unsigned integer will be smaller or equal as 0xFFFF for
> every possible value.
> Loops forever and no need to change i at any time.
> 
> regards
> 
> Michael

-- 
  +--------V--------+   address@hidden
  |  A L C A T E L  |   -----------------------------
  +-----------------+   Phone: +43 1 27722 3706 
         T A S          Fax:   +43 1 27722 3955



reply via email to

[Prev in Thread] Current Thread [Next in Thread]