Hacker News new | ask | show | jobs
by TorKlingberg 4387 days ago
Yes, C doesn't have generics. In practice most C code uses the fourth version, and you just have to remember not to put things with side effects as macro arguments.

#define MIN(a, b) ((a) < (b) ? (a) : (b))

C11 does introduce very limited type-variant macros.

1 comments

Yep, but for min the C11 generics would work just as well and allow for a bit more flexibility than the older approaches.

Though you do have to name mangle manually and they aren't quite as powerful as you'd probably want.

http://www.robertgamble.net/2012/01/c11-generic-selections.h...