Get the latest tech news
Implementing Generic Types in C
There are various ways, but some are better than others.
We’ve gotten rid of the backslashes, we get proper syntax highlighting, and by just adding a#define T int line temporarily we get type checking and autocompletion and all that good stuff. The type erasure( void*) approach only makes sense if FFI or dynamic linking is involved, or you really must avoid code bloat at all costs. For more complex data structures than a dynamic array you’ll want to shift as much work to helper functions as possible, making it a bit of a hybrid with the void* approach.
Or read this on Hacker News