2 ms·
Unless I’m missing something, I don’t really see the point of putting the functions in the struct instance since it doesn’t seem like you need to use any form o
by variadix 2y ago
Unless I’m missing something, I don’t really see the point of putting the functions in the struct instance since it doesn’t seem like you need to use any form of polymorphism/function overriding.
If you have normal, non-virtual instance methods you are better off making it a normal function with some class centric naming pattern, e.g. JSON_Parse(JSON* self, const char* json).
If you want to emulate virtual functions from C++ you are better off storing a single pointer to a statically allocated vtable of function pointers (1 instance per class), that way your instance structs are smaller at the cost of an extra indirection per virtual call. You could also go the Rust route and use a large pointer type (pointer to object + pointer to vtable) for polymorphic objects that avoids a longer dependency chain at the cost of larger object pointers.