Hacker News new | ask | show | jobs
by hiimnate 3688 days ago
But can't you write it so that it is contiguous using a pointer?
2 comments

No, because a pointer points to some location in memory, not whatever follows the memory after the location of the pointer.

See [0] for a picture.

[0] http://c-faq.com/aryptr/aryptr2.html

You can

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

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

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