Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The irony is that arrays in C are in fact generic. As that is the simplest generic solution that doesn't require boiling the ocean first, that's what many programmers reach for.


How do I write a C function which operates on array of type T?

Which generic operations does the language provide?


Arrays are generic, but of course C doen't provide generic functions.

You can generically copy arrays [1], index them, iterate them, compute their size. But that's not the point, the point is that you can instantiate them for any (complete) T.

[1] well, C is weird, so you first need to wrap them in a struct.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: