Polymorphism through interfaces (Go) and traits (Rust) can be implemented in C using structs and function pointers. The article walks through multiple approaches, starting with naive implementations that have memory overhead and layout dependencies, then evolving to a method table pattern that stores interface methods
Table of contents
Interfaces in GoTraits in RustToy exampleInterface definitionInterface dataMethod tableAlternative: Method table in implementorBonus: Type assertionsFinal thoughts1 Comment
Sort: