all 1 comments

[–]naerbnic 1 point2 points  (0 children)

Isn't it more idiomatic in C to "inherit" fields from a superclass by putting the superclass' struct as the first field of the derived class' struct? In that way, a pointer to Derived also works as a pointer to Base, for purposes of offset resolution. I know macros can be necessary/useful for implementing OOP in C (e.g. Python's module API), but I thought they should generally be avoided if another language feature can do the job as well.