Not exactly.
You can even create a tool to read the generic code and generate the concrete for each type. It's hard, hard work, easy to do wrong, and probably does not pay.
It's always possible to try something creative with macro, but it will be pretty bad.
If you are using C11 you have the _Generic
macro. I do not think it looks good. And it's not something that's usually used, actually I've never seen a code using it. The idea is that if you need this use C ++ and be happy.
A practice that is often used in such cases is polymorphism, but it loses type security and there is a small loss of performance.
Instead of using a specific type, use void *
, so the type is generic, whatever is used will be accepted. In compensation you can send anything you accept, unless you create a logic trying to prevent the error, which is not simple to do right in C. In general the custom is to trust that the programmer will use certain.
C is a weak typing language with low type security. One of the reasons for creating C ++ is to solve this problem.
You have a basic example .