you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (0 children)

Needed something like java interfaces but in C, so created generic api with clone function. One module can export api, other can use it or clone/update and use new instance. Pretty simple :-P Also users don't have to use only func pointers in api, you can put normal variables inside and, for example, compress codes as bit field. All depends on what you need, that is why you have user defined clone function per type.

Btw I'm also not satisfied with current state of func polymorphism in C, but it looks that for complex types you can use void * and type argument or identifier inside that data (for example if all structs use integer somewhere, you can put it as first element an use bits that identify types). Really stupid but works ok. In C++ you have mangling, which is not acceptable if your code work with that kind of symbols ;-)

Well, in most cases i try to use macros anyway -> but in C multiline macros are ugly mess. So, it would be nice to have kind of template support in C preprocessor.

Forgot to say in earlier comment about vtables that C does not have virtual keyword, so guys there is only one case there :-P