Цитата(MrYuran @ Sep 7 2012, 15:51)

GCC позволяет включать в структуры открытый массив, если он размещен последним.
Это (иметь такой массив в структуре) позволяет C99.
Цитата
6.7.2.1 Structure and union specifiers
...
Semantics
...
16 As a special case, the last element of a structure with more than one named member may have an incomplete array type; this is called a flexible array member. With two exceptions, the flexible array member is ignored. First, the size of the structure shall be equal to the offset of the last element of an otherwise identical structure that replaces the flexible array member with an array of unspecified length. Second, when a . (or ->) operator has a left operand that is (a pointer to) a structure with a flexible array member and the right operand names that member, it behaves as if that member were replaced with the longest array (with the same element type) that would not make the structure larger than the object being accessed; the offset of the array shall remain that of the flexible array member, even if this would differ from that of the replacement array. If this array would have no elements, it behaves as if it had one element but the behavior is undefined if any attempt is made to access that element or to generate a pointer one past it.
Просто инициализация такого массива не входит в планы :-)
Зато позволяется такое (можете пробовать с -std=c99 --pedantic):
Код
#include <stdlib.h>
typedef struct {
int head, tail, size;
int data[];
} fifo_t;
fifo_t *create_fifo(int size)
{
fifo_t *pf = (fifo_t*)malloc(sizeof(fifo_t)+size*sizeof(int));
if (pf) {
pf->head = pf->tail = 0;
pf->size = size;
}
return pf;
}
...
// И затем так
pf->data[head++] = a;
// Что абсолютно корректно, так как
// it behaves as if that member were replaced with the longest array
// that would not make the structure larger than the object being accessed
Думаю, для этого в стандарт и было введено. До C99 извращались так:
Код
typedef struct {
int head, tail, size;
int data[1];
} fifo_t;
fifo_t *pf = (fifo_t*)malloc(sizeof(fifo_t)+(size-1)*sizeof(int));
Некоторые компиляторы в качестве расширения позволяли
Код
typedef struct {
int head, tail, size;
int data[0];
} fifo_t;