Live data from Hacker News

Object-Oriented Programming in C (2019) [pdf]

state-machine.com

1–10 of 95 posts

Re: Object-Oriented Programming in C (2019) [pdf]

#3
Unfortunately with this approach to inheritance PIMPL goes out the window, since the class structs are now all public to facilitate embedding...

And despite this public visibility of the object's struct members granted to provide inheritance, the examples are still using getters and setters.

Ok...

Re: Object-Oriented Programming in C (2019) [pdf]

#5
post #3

Unfortunately with this approach to inheritance PIMPL goes out the window, since the class structs are now all public to facilitate embedding... And despite this public visibility of the object's struct members granted to provide inheritance, the examples are still using getters and setters. Ok...

[deleted]

Re: Object-Oriented Programming in C (2019) [pdf]

#6
I think this approach is working too hard to realize Virtual Tables and Virtual Pointers. Another, different implementation is to define an array of function pointers, one function per method implemented, and then extend the array per subclass; each child class fills in its own or parents function pointers at init time.

Re: Object-Oriented Programming in C (2019) [pdf]

#7
1. Creating a struct with desired state data

2. Creating functions that take a pointer to the struct as the first parameter

3. Declaring a variable with that struct type to create an instance of the object

4. Declaring another variable with that struct type for another object instance

Re: Object-Oriented Programming in C (2019) [pdf]

#9
post #3

Unfortunately with this approach to inheritance PIMPL goes out the window, since the class structs are now all public to facilitate embedding... And despite this public visibility of the object's struct members granted to provide inheritance, the examples are still using getters and setters. Ok...

Once you implement these design parameters, you've essentially written the GObject type system. Might as well use GObject at that point and get tons of language bindings for free.

("Free" after adding some metadata comments specifying parameter ownership/lifetimes, at least.)

Re: Object-Oriented Programming in C (2019) [pdf]

#10

I think this approach is working too hard to realize Virtual Tables and Virtual Pointers. Another, different implementation is to define an array of function pointers, one function per method implemented, and then extend the array per subclass; each child class fills in its own or parents function pointers at init time.

What would also be helpful is a standard way to declare to the compiler that it should or should not optimize each flagged polymorphic late bound call implementation to be early bound; moving the calls into separate or merged files during linking is not an in context solution.
Post reply on HN