3 ms·
You can x = malloc(sizeof(x) + <variable_length>); x->ptr = x + sizeof(x);
by jmpeax 10y ago
You can
x = malloc(sizeof(x) + <variable_length>);
x->ptr = x + sizeof(x);
- imron 10y agoExcept it requires sizeof a pointer more memory and an extra assignment after the malloc, which is why people use the zero-sized array instead (note this comment was to explain for the grandparent why you would normally prefer a zero-sized array instead).