Macros

1

Generics: Stop Using void Pointers for Generic Code

5 minute

C has several common ways to write generic code:

  • void * plus size and callbacks
  • macros that generate code for different types
  • duplicated functions for different concrete types

All of them work, but each has a cost. void * loses type information, macros are harder to debug, and duplicated functions drift.

Rust generics solve the same problem: one piece of code can work for multiple types while keeping type checking.

Read More