I don’t understand why
struct e{
void * a;
void * b[];
}
has sizeof(e) == 4 while
struct f{
void * a;
void * b;
}
has sizeof(f) == 8.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The second in the first struct is not a pointer, but a FAM – flexible array member. It is used when you have a long buffer and place an
eat the start of that buffer. You can then index the remaining memory that follow theeobject using that FAM and treat that memory as an array ofvoid*.The Standard says (emphasis by me)
For example, the following code outputs
1for the struct without, but4for the struct with the FAM on GCC, because to access integers the FAM need to be properly aligned (on a 4 byte boundary in this example)