Tech article
Type Safe Generic Data Structures in C
No preview is available. Read the original article for the full story.
Hacker News | Oct 3, 2026 | AlexeyBrin
Automated excerpt
See my follow-up article: “A Fast, Growable Array With Stable Pointers in C”I write type safe generic data structures in C using a technique that I haven’t seen elsewhere1. It uses unions to associate type information with a generic data structure, but we’ll get to that. Using a union makes payload not consume any memory. If you’re writing a generic function that needs to return a pointer to contained data, you can use __typeof__() to cast the return type from void * to the data structure’s payload type.
Selected automatically from source text; not independently written or fact-checked. Read the original for full context.