My hunch is that it works on another compiler, but not gcc.
The problem lies not with the compiler but with the fact that whoever wrote that code only tested it with C-compilation1
. Had they run the code through ANY C++ compiler they would be having the same problems you're having.
This compiles and should work correctly...
static __inline__ void
eeprom_write_block (const void *__src, void *__dst, size_t __n)
#if (! (defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__)) )
__eewr_block (__dst, __src, __n, eeprom_write_byte);
/* If ATmega256x device, do not call function. */
eeprom_write_byte( (uint8_t*)__dst, *(uint8_t *)__src );
__src = (uint8_t*)__src + 1;
__dst = (uint8_t*)__dst + 1;
Don't worry about optimization. Writing to EEPROM is a very slow operation. Relatively speaking, a few extra machine instructions is going to make no difference.1
The code may not even be compilable C. I'm too lazy to test and too ignorant to know for certain.