Does a flexible array member increase sizeof a struct?

后端 未结 2 866
陌清茗
陌清茗 2020-12-10 15:59

I have the following kind of code:

typedef struct
{    
    u32 count;
    u16 list[];   
} message_t;
...

message_t* msg = (message_t*)buffer;  
msg->co         


        
2条回答
  •  不知归路
    2020-12-10 16:29

    Here's what the standard says:

    As a special case, the last element of a structure with more than one named member may have an incomplete array type; this is called a flexible array member. In most situations, the flexible array member is ignored. In particular, the size of the structure is as if the flexible array member were omitted except that it may have more trailing padding than the omission would imply.

提交回复
热议问题