Pages: 1 [2]   Go Down
Author Topic: Function fails with passed in variable, but works if set manually.  (Read 1098 times)
0 Members and 1 Guest are viewing this topic.
SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 106
Posts: 6381
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Des Moines, Iowa, USA
Offline Offline
Jr. Member
**
Karma: 0
Posts: 52
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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 smiley  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.
Logged

Embedded Software Engineer
UNO | Leonardo | Due | Teensy | BASIC Stamp
http://www.subethasoftware.com

Pages: 1 [2]   Go Up
Jump to: