Lambda the Ultimate

inactiveTopic Object-Oriented C
started 2/17/2001; 2:50:36 PM - last post 2/18/2001; 3:27:24 AM
Chris Rathman - Object-Oriented C  blueArrow
2/17/2001; 2:50:36 PM (reads: 720, responses: 2)
Object-Oriented C
More a personal interest of my own, since I am looking at a prospect of software written in C (along with various other languages) for an embedded system that uses Object-Oriented techniques. Nicer when the language actually supports OOP, but sometimes you don't have that luxory.
Posted to OOP by Chris Rathman on 2/17/01; 2:52:09 PM

andrew cooke - Re: Object-Oriented C  blueArrow
2/18/2001; 12:25:25 AM (reads: 720, responses: 0)
This is a really useful technique - it's used inside some major C projects (one example is OpenSSL).

What this article doesn't seem to mention (but I only skimmed) is that you can enforce hiding (no access to private methods and data) by splitting header files into public and private. In the public definition of the object, include a void* private field; in the private definition you can define a private structure that this will point to. Private methods then cast the void* to the correct structure and manipulate it as required.

If other code only imports the public header then they have no way of accessing the private structure.

I learnt this at my previous employer, maintaining code written by an employee who had left before I arrived and who had a reputation as being "too clever" by those that remained. Given the standard of the rest of the company (only his code was written as OOC), I regret never having met him...

...on the other hand, it can be difficult to read (grep for private to see an example of what I describe above) and difficult to debug. Apart from inheritance, I think the big advantage of C++ over C is that it makes reading and debugging this style easier.

Ehud Lamm - Re: Object-Oriented C  blueArrow
2/18/2001; 3:27:24 AM (reads: 754, responses: 0)
Apart from inheritance, I think the big advantage of C++ over C is that it makes reading and debugging this style easier.

If you want readability, use Ada