Is empty array in the end of the structure a C standard? -


i have noticed empty array in end of structure used in open source projects:

typedef struct {     ......     void *arr[]; } a;   

i want know c standard? or ok gcc compiler?

as of c99, c standard. pre-c99 compilers may not support it. old approach declare 1-element array, , adjust allocation size that.

new way:

typedef struct {     ......     void *arr[]; } a;    int slots = 3; a* mya = malloc(sizeof(a) + slots*sizeof(void*)); mya->arr[2] = foo; 

old way:

typedef struct {     ......     void *arr[1]; } a;    int slots = 3; a* mya = malloc(sizeof(a) + (slots-1)*sizeof(void*)); mya->arr[2] = foo; 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -