I am trying to convert a struct consisting of the following:
struct myData
{
double value1;
int32_t value2;
bool flag;
int32_t value3;
int32_t value4;
bool flagArray[32];
}
I wanted to convert this struct into an unsigned char array so that I can apply CRC from an open source (http://www.netrino.com/code/crc.zip). However I noticed that the bool var will be automatically typecast into a var with 4 bytes (in which 3 bytes are undefined). Hence, the CRC checksum may fails if it is received and interpreted differently from the sender.
May I know is there any way that I can resolve this problem?
Thanks
doubleis a bit problematic). A semi-portable way would be to replacebool flagwithuint32_t flag,bool flagArray[32]withchar flagArray[32]or evenuint32_t flagArray; usehtonl, and check that sizeof(struct myData) is the sum of the size of the elements.