Is using flexible array members in C bad practice? -
i read using flexible array members in c poor software engineering practice. however, statement not backed argument. accepted fact?
(flexible array members c feature introduced in c99 whereby 1 can declare last element array of unspecified size. example: )
struct header { size_t len; unsigned char data[]; };
the reason give not doing it's not worth tie code c99 use feature.
the point can use following idiom:
struct header { size_t len; unsigned char data[1]; };
that portable. can take 1 account when allocating memory n elements in array data
:
ptr = malloc(sizeof(struct header) + (n-1));
if have c99 requirement build code other reason or target specific compiler, see no harm.
Comments
Post a Comment