3 ms·
In the first example it says the error is failing to allocate space for the null byte: struct str { size_t len; char data[]; }; struct str *str = malloc(
by angry_octet 3y ago
In the first example it says the error is failing to allocate space for the null byte:
struct str {
size_t len;
char data[];
};
struct str *str = malloc(sizeof(str) + len);
But is this an idiom for doing Pascal style strings?
That sizeof(char buf[]) returns 0 is interesting, perhaps only in a struct? A case where it isn't equivalent to char *. And now I'm wondering what sizeof would return for:
struct str {
size_t len;
char data[];
char nullbyte;
};
Presumably str.data would be the same value as &str.nullbyte?