all 5 comments

sorted by: hot top controversial new old
[–] 8 points 1 year ago* (4 children)

I was working on a C code base with classes, inheritance, and polymorphism, all done by hands and macros.

Something like

typedef struct s_some_class {
    void (*method)(this *s_some_class);
} t_some_class;

Overall, learning C was the best enabler in my whole career. For instance I was learning Python by tinkering with CPython VM, so when I see these ‘WAT’ quircks I know exactly what’s up.

  • source
  • hideshow 4 child comments
  • [–] [S] 4 points 1 year ago (3 children)

    Interesting, how did they do inheritance? Something like void *super? Also why not switch to CPP if you wanna do OOP?

  • source
  • parent
  • hideshow 3 child comments
  • [–] 2 points 1 year ago (2 children)

    In general, 'classes' declarations were done with macro. I don't remember the exact code — something akin to

    BEGIN_CLASS(A, Parent);
    CLASS_MEMBER(a...)
    END_CLASS();
    

    The project had started before C++ existed, and the switch would be too costly. It's not just OOP part, also reflection mechanism with bindings to the homemade scripting language, and multi-platform UI library. It was a gem of its time.

  • source
  • parent
  • hideshow 2 child comments