How to write type-safe generics in C