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

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -