Hacker News new | ask | show | jobs
by flohofwoe 48 days ago
The most idiomatic and elegant 'dynamic array in C' solution is stb_ds.h, it's as simple as that :)

The 'public handle' is a pointer to the array elements so it has the same semantics as a regular C array, the meta-data (capacity and length) are stored directly in front of the array items. Growing the array has the same behaviour as realloc (e.g. you may get a new pointer back).

1 comments

Thanks for mentioning it, I've heard about stb, but this time around I actually looked at the code. Their approach is very nice.