Suppose I have a structure of the type below:
struct employee
{
int emp_id;
int name_len;
char name[0];
};
I know that
struct employee *e = malloc(sizeof(*e) + sizeof(char) * 128);
is equivalent to
struct employee
{
int emp_id;
int name_len;
char name[128]; /* character array of size 128 */
};
My question is Can I create an array of such structures when the last element in the structure is struct hack.
Example:I want to create a an array of structures employee[3]; So that
employee[0] can be equivalent to
struct employee
{
int emp_id;
int name_len;
char name[128]; /* character array of size 128 */
};
employee[1] can be equivalent to
struct employee
{
int emp_id;
int name_len;
char name[256]; /* character array of size 256 */
};
employee[2] can be equivalent to
struct employee
{
int emp_id;
int name_len;
char name[512]; /* character array of size 512*/
};