I have the following code:
typedef struct { u32 count; u16 list[]; } message_t; ... message_t* msg = (message_t*)buffer; msg->count = 2; msg->list[0] = 123; msg->list[1] = 456; size_t total_size = sizeof(*msg) + sizeof(msg->list[0]) * msg->count; send_msg( msg, total_size );
The problem line is a line with sizeofs. I'm not sure if this is the right way to calculate the required space. Does sizeof(*msg) have anything about a list member?
I can check it with my compiler, but does each compiler work in this case?
source share