!#%$ casts


please take @ http://www.arduino.cc/cgi-bin/yabb2/yabb.pl?num=1278172720
i've been struggling (mostly brute force trial , error) fix code in eeprom.h, deep in bowels of arduino. code conditionally included if processor 2560. although in current system source doesn't compiled. hunch works on compiler, not gcc.

perhaps part of leaves me confused trying understand casts rules seem interpreted differently in different compilers , find varying explanations of c++ casts on web. anyway 1 case worked out sort of solution seems awkward , wordy , therefore seems inappropriate fundamental part of system. there must way compiler agree "copy anything", original code seems quite tell do.

unfortunately think problem way more pervasive 2 instances posted, seems me if can write syntax elegantly once, understand how on , over.

quote
my hunch works on compiler, not gcc.

the problem lies not compiler fact whoever wrote code tested c-compilation1.  had run code through c++ compiler having same problems you're having.

this compiles , should work correctly...
code: [select]
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);
#else
 /* if atmega256x device, not call function. */
 while (__n--)
 {
   eeprom_write_byte( (uint8_t*)__dst, *(uint8_t *)__src );
   __src = (uint8_t*)__src + 1;
   __dst = (uint8_t*)__dst + 1;
 }
#endif
}


don't worry optimization.  writing eeprom slow operation.  relatively speaking, few machine instructions going make no difference.


1 code may not compilable c.  i'm lazy test , ignorant know certain.


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > !#%$ casts


arduino

Comments