Hi,
does someone have a trick to dynamically check the size of a struct before sending it on radio with memcpy orto write/read in EEPROM or flash?
Maybe I'm cheated by my IDE (Visual Micro) but when I use sizeof(mystruct), as a struct is a collection of pointers, my IDE tells me sizeof(mystruct) is the size of the pointers collection and not the actual size of data which makes sens for me. Since a struct can contain byte, int, long, char... etc I don't know how to know the memory size of the data without defining a constant manually (which is a source of later problem)
I wonder if my IDE is reliable or if I should not believe it... in the code of EEPROMex library, to save a struct we can use the updateBlock function which use "sizeof" function to know how many bytes to write
template <class T> int updateBlock(int address, const T& value)
{
int writeCount=0;
if (!isWriteOk(address+sizeof(value))) return 0;
const byte* bytePointer = (const byte*)(const void*)&value;
for (unsigned int i = 0; i < (unsigned int)sizeof(value); i++) {
if (read(address)!=*bytePointer) {
write(address, *bytePointer);
writeCount++;
}
address++;
bytePointer++;
}
return writeCount;
}