I have 2 functions in C doing exactly the same thing, the only difference is the data types passed to each function e.g. one is int the other one char* .
Is there a way to combine these functions to one so that when I call this one function I need not worry about the data type. This can be done in C++ using template but I want to do the same thing in C and do not know how, thx.
I have 2 functions in C doing exactly the same thing, the only difference
Share
I know two common ways to deal with such situtation in C.
1)Replace int and “char *”, with “void *p” and “int size”
for example see qsort from stdlib
2)Use preprocessor, like
things like this used to emulate std::list in linux kernel.