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

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

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


From: Peter N Lewis
Subject: RE: [avr-gcc-list] An old but unfixed bug
Date: Wed, 22 Aug 2001 09:13:37 +0800

Hi Alexander,  I don't think this is a gcc bug per se.  Your while condition
is comparing an int (0xffff == -1) cast to a pointer.  If your pointer p is
initialised to any value <= 0x7fff your while condition fails on the first
pass.  The source file you sent showed p = RAMEND + 1.  Usually a small
positive number (eg. 4433 --> 0x15F + 1) so you have:
        while ( 352 < -1 );  // fail

Yes, that would be true, except that it fails even if p is initialized large enough to be "negative".

        unsigned char *p;
        p=(unsigned char*)0x9000;
        do {
          *p = 1;
        } while(p++<(unsigned char *)0x0ffff);

That does the same thing (compiles to just *0x9000 = 1;)

I agree it is probably a signed issue, and it can be fixed by changing the file line to:

        } while((unsigned int)(p++)<(unsigned int)0x0ffff);

it still rates as a bug to me. Treating pointers as unsigned seems a bit dubious at the best of times, but the optimization is definitely bogus given they are both support to be (unsigned char *) and are both the same sign (or unsigned).

If I remember correctly though, C does not specify that pointer inequality comparison will work for any pointers not in the same array. However, it still needs to correctly handle pointers into an array that spans $8000...

Enjoy,
   Peter.

--
<http://www.interarchy.com/>  <ftp://ftp.interarchy.com/interarchy.hqx>



reply via email to

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