OnlyGenerics In C

Introduction C doesn’t have templates, but it does have the preprocessor. If you’re careful, you can get something that feels like std::vector<T> without switching languages. It’s not perfect and it’s not type theory, but it is surprisingly usable. This post is about that: cheap macro tricks that give you “templated” types in plain C. The Core Trick You first define a generic backing struct. Then…