Why some struct uses a single element array, such as follows:
typedef struct Bitmapset
{
int nwords;
uint32 words[1];
} Bitmapset;
To make it convenient for latter dynamic allocation?
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.
In a word, yes.
Basically, the C99 way to do it is with an flexible array member:
Some pre-C99 compilers let you get away with:
But the way to guarantee it to work across all compilers is:
And then, no matter how it’s declared, you can allocate the object with:
Though for best results you should use
size_tinstead ofint.