Object Oriented Programming in C

One of the C projects I’m working on needed some object oriented features of the type one would normally use C++ for. I thought it shouldn’t be too hard to do some minimal OO stuff in C and it turns out there are plenty of examples and complete frameworks out there to help. If you’d like a complete OO framework for C, Laurent Deniau’s webpage, Object Oriented Programming in C, is a good place to start. The most interesting system described is the C Object System (COS) which is described as “strongly inspired from CLOS and Objective-C and to a lesser extend by Cecil, Dylan, Haskell, Python, Slate and SmallTalk”. The description also notes that COS provides dynamic message dispatching that’s up to 1.5 times faster than Objective-C and generic message forwarding that’s up to 80 times faster than Objective-C. COS is designed to match the simplicity, flexibility, and extensibility of Python, Ruby, or Smalltalk while retaining the efficiency and portability of C. The COS framework is licensed under the LGPL. Pretty cool.

Laurent also describes the Object Oriented C (simplified) framework, which is a small (300 sloc) pile of code derived from OOC-2.0 that provides C programmers with a feature set similar to Java. There’s also “Exception in C”, which provides a Try-Catch-Finally implementation for C.

I also found Axel-Tobias Schreiner’s book, Object Oriented Programming in C very helpful. A PDF version of the book is available online (alternate link).

Leave a Reply

Your email address will not be published. Required fields are marked *