Double EEPROM memory entry Atmege 328p

I disagree and don't see that as an hijacking. I think it's a fair question given it's not obvious what happens as the doc states

value: the value to write, from 0 to 255 (byte)

and I'm not using a byte but an int type. Good opportunity to discuss promotions.

I think we had a recent discussion where I explained about implicit promotions (the float being truncated into an integer). Here it's the same thing, the write() function expects a byte so C++ will apply an int to byte implicit conversion which basically takes the least significant byte of the variable as is (bit for bit) and that's what makes it to the write() function. as my index does not go over 255 nor goes negative, it's the exact index value that gets written in EEPROM

1 Like