Share your repls and programming experiences

← Back to all posts
Object Oriented C - except it works!
proofofconcept (21)

It was painful, but I got the object oriented C to work. Here's how:

  • When an object is created, its function pointers are initialized to addresses. These addresses point to machine code that the program has created.
  • This machine code is edited at runtime, allowing for a function's behavior to be determined at runtime. Specifically, it is designed to call the corresponding function with one of the parameters being a pointer to the struct. It shifts all other arguments down.
  • The machine code has to be mapped into an executable page to prevent unwanted segmentation faults.
  • When the function is called, the program calls this machine code, which provides the member function with a pointer to the struct so that it can properly behave.
    In this program, we create a class called Point and then initialize an object of that type. We use the getx() and gety() functions to demonstrate the system.
    I'm sure that this system is deeply flawed and will really never work due to some huge oversight, but at least it seems to work.
    ...any questions?
kidd81 (0)

Obviously Chicago bound

MatthewDoan1 (331)

Wow, this is a pretty impressive