A C Of Polymorphism Without CPP

Introduction Polymorphism sounds like a C++ word. In C, it still exists, just without the sugar. You create a base type, keep a table of function pointers, and pass that base pointer around. A Small Example Here’s an example. This is the base class. typedef struct Animal Animal; struct Animal { char * name; void ( * speak)(Animal * self); }; Now the child types. typedef struct { Animal base; }…