Due and PROGMEM - not compatible?

I am trying to write code compatible for both AVR and the Due, but have run into a problem with using PROGMEM on the Due. Here is a demo snippet:

const prog_int16_t junk[2] PROGMEM = { 1234, -1234};

void setup() { Serial.begin(9600); int junk1 = pgm_read_word_near(junk + 0); int junk2 = pgm_read_word_near(junk + 1); Serial.print(junk1); Serial.print("\t"); Serial.println(junk2); }

On a Uno etc it reports correctly: 1234 -1234 as it should, but on a Due it reports 1234 64302 in other words it returns a uint16_t . I have tried all weekend to solve the problem, including redefining the macro, casting the output, etc. The only way I have found is to do a 2's complement sign reversal on the output: if (val & 0x8000) val -= 65536; There has to be a better way?

Is this a known bug.

Derek

Progmem is not necessary on the Due and AFAIK not supported although if you didn't get a compiler error there must be something behind pgm_read_word_near().

Maybe find out where that's defined and see what it does, but also you could just #define it out of existence if the code is on a Due.

What do the official libraries do, surely this has been dealt with by them.


Rob