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

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

RE: [avr-gcc-list] Possible bug in avr-gcc 4.3.2?


From: Zoran Rilak
Subject: RE: [avr-gcc-list] Possible bug in avr-gcc 4.3.2?
Date: Mon, 25 May 2009 21:22:18 -0400

On Tue, 2009-05-26 at 10:46 +1000, Michael wrote:
> I think I may know the problem. 
> 
> Not only are your strings are stored in program memory, but also your
> pointers to these strings are stored in program memory. 

Thanks Michael and others who bothered to reply,

indeed, I borked up the access to program space, as many have kindly
pointed out, but more interestingly:

uint8_t k = 1;
uint8_t l = now.dow;      // will be 1 at runtime

lcd_write_int16(dow[k]);  // outputs: address of dow[1] in PGM
lcd_write_int16(k==l);    // outputs: 1 (as it should)
lcd_write_int16(dow[l]);  // outputs: 0

Turns out that GCC optimizes out k and replaces dow[k] with the
appropriate value from array initializer.  At runtime, dow[l] is
(correctly) dereferenced to data space, while dow[k] has been
substituted with a hardcoded pointer to program space at compile-time.

Lesson learned. =)

Zoran






reply via email to

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