Alocando struct com membro de matriz flexível
Este é o código C99:
typedef struct expr_t
{
int n_children;
foo data; // Maybe whatever type with unknown alignment
struct expr_t *children[];
} expr_t;
Agora, como aloquei memória?
expr_t *e = malloc (sizeof (expr_t) + n * sizeof (expr_t *));
ou
expr_t *e = malloc (offsetof (expr_t, children) + n * sizeof (expr_t *));
?
Ésizeof
mesmo garantido para trabalhar em um tipo com membro da matriz flexível (GCC aceita)?