This thing has been bothering me for some time now...
I have a program where I load variables of varying sizes from EEPROM. I use a special function for this. I need to use different version of this function depending on the size of the variable to read, however I don't want to explicitly specify it when coding (especially since some variable types could be changed in near future). In C++ you can simply define polymorph functions, i.e. same name but different return types. This is not supported by WinAVR, correct?
I tried doing it with macros, sth like this:
#define eeprom_read_poly(dest, eesource) ( #if sizeof(dest) == 1 (dest = eeprom_read_b8((unsigned char*) &eesource);) #endif #if sizeof(dest) == 2 (dest = eeprom_read_b16((unsigned char*) &eesource);) #endif #if sizeof(dest) == 4 (dest = eeprom_read_b32((unsigned char*) &eesource);) #endif
however it does not compile, I get the error
missing binary operator before token "("
for each line with sizeof().
Surely there is a way to implement this. Note that this is merely for conveniency; I can write code that implements the loading, but not the "correct" way...
Any help is appreciated.
Oh, I forgot one thing - I love WinAVR!