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).

Random News

Not much to report today. Most of the day was spent debugging C++ code. (if there was a bed here at the office, I’d never need to go home!) Programming in Perl can spoil you really quick. It takes a lot of C or C++ code to do what Perl can do in one or two lines.

The SETI@home server was down for several hours today and, unfortunately for me, the downtime coincided with the completion of about four work units – which apparently got sent to the bit bucket. This caused me to fall back to 7th place on Team Slashdot. I’m confident that I’ll regain 6th place tomorrow though, as I have upgraded the three Windows machines to run the new CLI client instead of the tediously slow GUI version. This change should help them keep up with the Solaris and Linux boxes and provide a gain of several work units per day.