pgm_read_word reads long as 2 bytes

I have:

const long colorVals[] PROGMEM = { 0xF0F8FF, 0xFAEBD7, .....

Serial.println( (long)(pgm_read_word(&colorVals[0])) ); This returns the value of 0xF8FF

Serial.println( sizeof(pgm_read_word(&colorVals[0])) ); And surprisingly, this returns 2.

What am I doing wrong?

You do not read the documentation?

http://www.atmel.com/webdoc/AVRLibcReferenceManual/group__avr__pgmspace.html

What am I doing wrong?

Casting a word (int) as a long doesn't make it so.

Taking the size of a function doesn't make sense.

sizeof(function()) returns the size of the return value of the function.

long lFunc() {
  return 2;
}
int iFunc() {
  return 1;
}
byte cFunc() {
  return 0;
}
void setup() {
  Serial.begin(250000);
  Serial.print(F("sizeof(cFunc()) "));
  Serial.println(sizeof(cFunc()));
  Serial.print(F("sizeof(iFunc()) "));
  Serial.println(sizeof(iFunc()));
  Serial.print(F("sizeof(lFunc()) "));
  Serial.println(sizeof(lFunc()));
}
void loop() {}
sizeof(cFunc()) 1
sizeof(iFunc()) 2
sizeof(lFunc()) 4

You want pgm_read_dword(…)

Hmm. C++ could “fix” this…

Whandall: You do not read the documentation?

http://www.atmel.com/webdoc/AVRLibcReferenceManual/group__avr__pgmspace.html

Never knew that it existed. Thanks