<p>I recently read that using flexible array members in C was poor software engineering practice. However, that statement was not backed by any argument. Is this an accepted fact?</p>

<p>(<a href="https://en.wikipedia.org/wiki/Flexible_array_member" rel="noreferrer">Flexible array members</a> are a C feature introduced in C99 whereby one can declare the last element to be an array of unspecified size. For example: )</p>

<pre><code>struct header {
    size_t len;
    unsigned char data[];
};
</code></pre>

You meant...
```
```
struct header
{
 size_t len;
 unsigned char data[];
};
```
```
In C, that's a common idiom. I think many compilers also accept:
```
```
unsigned char data[0];
```
```
Yes, it's dangerous, but then again, it's really no more dangerous than normal C arrays  - i.e., VERY dangerous ;-) . Use it with care and only in circumstances where you truly need an array of unknown size. Make sure you malloc and free the memory correctly, using something like:-
```
```
foo = malloc(sizeof(header) + N * sizeof(data[0]));
  foo->len = N;
```
```
An alternative is to make data just be a pointer to the elements. You can then realloc() data to the correct size as required.
```
```
struct header
    {
     size_t len;
     unsigned char *data;
    };
```
```
Of course, if you were asking about C++, either of these would be bad practice. Then you'd typically use STL vectors instead.