无长度数组

CODE:

struct Unkown {
    int len;
    char data[0];
    /* do not write fields below */
};
/* sizeof(Unkown ) = 4 */

Unkown *p;
int n = 100, i;
p = malloc(sizeof(Unkown ) + n);
for (i = 0; i < n; ++i)
    p->data[i] = 1;
p->len = n;

你可能感兴趣的:(struct)