suppose I have the following struct declaration
struct m27
{
uint64_t head ;
int vp_array[500] ;
float lpx[500] ;
s_ent ent[500*plno] ;
uint32_t crc ;
};
prior to writing to disk or transmitting over the network I wish to compute the crc value. I need to get the number of bytes excluding the last field The best that I have come up with is
((char*) &(((m27*) secspec)->crc)) - ((char*)&(((m27*) secspec)->head))
where secspec is a void
pointer that points to a struct of type m27
This seems rather cumbersome and error prone however. The initially obvious of sizeof(m27)-sizeof(uint32_t)
does not work as it yields the wrong answer due to padding. Is there a better way?