Go Down

Topic: Function fails with passed in variable, but works if set manually. (Read 2046 times) previous topic - next topic

westfw

Yep.  I came up with the same fix as Pyro65, once I looked at it more carefully.
You didn't have ANY special code to read the pointers from flash...

Beats me why it worked with constants, though.  I guess the compiler did most of the pointer arithmetic at compile time, so the step where it fetched inappropriate pointers from RAM was skipped.



I really believe it's a compiler issue.

Nope,

Because your flasharray is an array of progmem pointers, not data. You must use pgm_read_word to retrieve the pointer.

Code: [Select]
Serial.println((__FlashStringHelper*)flashArray[i]);

This is reading the i'th value in sram, you placed the data in PROGMEM. I can see that it works on occasion for you ( and my test ), but it is still wrong.


Yes, agreed, and understood. That's what I pointed out I do in my production code (see my post from April 10, 2013).

My issue was not with that, at all,, but with the inconsistency I see with things being done behind the scenes with the compiler and preprocessor and such. I really expect I am doing more intense stuff than probably 99% of most Ardunio uses ever deal with :)  It's fun.

The challenge I faced was making code that could generate to use RAM or FLASH by altering a #define, to make it easy for end-users that do not get involved with how the tools work.
Embedded Software Engineer
UNO | Leonardo | Due | Teensy | BASIC Stamp
http://www.subethasoftware.com

Go Up