Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Yes, but it's not the same. :( { It is fun, though - I once did it to write/read a data structure with two levels of indirection (i.e. an array of arrays) - Slurp the whole thing to memory, then adjust the pointers, and voila. }

In C89 it's trickery and a little bit of black magic (at least a whiff of it), while in C99, it is an officially supported convention.

On x86, where the C code I wrote ran, it wouldn't make much of a difference, but allocating header + array manually also means - if the code needs to run across a variety of CPU architectures - that one needs to look at alignment issues.



IIRC You don't have to play with pointers if you use the null array trick (put an array of size zero at the end of your struct and use it anyway)




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: