Hacker News new | ask | show | jobs
by jmpeax 3697 days ago
You can

x = malloc(sizeof(x) + <variable_length>);

x->ptr = x + sizeof(x);

1 comments

Except 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).