Why, oh why... (WinAVR const array question)

Topics related to the API, programming discussions & questions, coding tips, bugs, etc. should go here.
Post Reply
havok1919
Posts: 474
Joined: Thu Aug 28, 2008 9:44 pm
Location: Vancouver, WA
Contact:

Why, oh why... (WinAVR const array question)

Post by havok1919 »

...do I have to do:

Code: Select all

sprites[9].tileIndex=pgm_read_byte(&(ship_frames[p1_direction]));
in WinAVR instead of just:

Code: Select all

sprites[9].tileIndex=ship_frames[p1_direction];
ship_frames is:

Code: Select all

const unsigned char ship_frames[] PROGMEM={34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49};
I'm assuming this is just my WinAVR newbieness showing... No warning or anything to let you know something's hosed... It had me confused for a while, so maybe someone else will be saved by that line of code. :)

-Clay
User avatar
uze6666
Site Admin
Posts: 4822
Joined: Tue Aug 12, 2008 9:13 pm
Location: Montreal, Canada
Contact:

Re: Why, oh why... (WinAVR const array question)

Post by uze6666 »

Yeah, I regularly forget that myself and curse when I can't understand the nonsense data that I read :oops:. That's my biggest gripe with the GCC compiler for AVR. They could have made that stuff automatic at compilation. But I've heard this compiler were never designed for Harvard-like architectures.

Anyhow, as you figured out, *any* data read from the ROM MUST use these macros. Otherwise you will read data from that address but in RAM and naturally get garbage.

Uze
Post Reply