3 ms·
Even though I got the quote right out of C99, I still mixed it up. The reason for this is that ... I don't use flexible array member myself or the [0] GCC exte
by kazinator 11y ago
Even though I got the quote right out of C99, I still mixed it up.
The reason for this is that ... I don't use flexible array member myself or the [0] GCC extension, either.
Flexible array member doesn't seem to bring anything to the table other than formal definedness of behavior. I can't imagine any implementation which supports flexible-array member in its C99+ modes, which makes [1] fail in the same modes or in the C99 mode. In any old compiler that doesn't have C99 support, that formally undefined struct hack is all you have.
I don't mind using offsetof(type, member) to obtain the size of the header before the array, rather than sizeof(type).
The classic hack is portable to C90 and C++98, making it good for "Clean C".
That said, flexible array member is elegant in the sense that it just uses an incomplete array type similarly to a file scope array declaration. Using [1] is a bit like while (1) instead of for (;;). I don't like the [1] in the struct hack, but I don't use C for its beauty.