Object Oriented Programming in C

Laurent Deniau

November 2006
Revised August 2007


[ COS | OOC-S | C Exception || OOC-2.0 | OOC-1.0 | OOPCC++ Object Model ]

Over the past years (2000-2008), I have developed some frameworks to explore various object models and simplify object oriented programming in C. This page contains some comments and links on these tentatives. All these frameworks try to achieve some general principles about programming which I consider of importance in the following order:

  1. Simplicity
  2. Flexibility
  3. Extensibility
  4. Efficiency
  5. Portability

The motivation to develop such frameworks on top of the C language may not be obvious. While many new languages appear each year with new syntax and little new concepts, I prefer to try to lift C up to the level of other high level languages. C is portable, efficient, widely available and standardized. This is probably why it is also the reference for other languages when memory and speed efficiency matter and why most languages have a Foreign Function Interface to C. Still, many virtual machines, interpreters, compilers or operating systems are written in C. If one often blame C to be a low level language similar to a super assembler, it should be worthwhile to raise C to the level of the other high level OO languages (and beyond?). This is the aim of the following frameworks entirely written in ISO C.

Supported frameworks
COS design is tuned to provide efficient portable implementation of these concepts, specially dynamic message dispatch (x1.7-x2.3 slower than an indirect function call and about x1.2-x1.5 faster than Objective-C) as well as generic message forwarding (as fast as message dispatch and about x40-x80 faster than Objective-C). On top of these concepts, it is easy to implement high order messages, class-predicate dispatch, multiple inheritance, dynamic inheritance, dynamic classes, adaptive object model, reflection and advanced memory management. It also simplifies the programming of multi-agent systems, distributed systems or adaptive systems. COS seems to achieve the principles 1-2-3 as well as existing mainstream scripting languages (e.g. PHP, Python, Ruby, SmallTalk) while keeping principles 4-5 in the range of C. Nevertheless, COS is compliant with POSIX threads and requires a (moderately compliant) C99 compiler.

Unsupported frameworks
For the moment, you can download [size=506kB] the tarball as-is. This code is NOT for software distribution and comes without any guarantee of any sort. I plan to use the GPL license for the first public release. The development was stopped during the phase of code cleaning and some work remains to make it clean and usable for large project. Part of the code do not compile (i.e. ooc-db module which was written on top of an old version of OOC-2.0) and the manual is obsolete but looking at the code of some classes should be enough to be able to use it. For the moment, this code is only provided for curiosity purpose, but if enough people are interested by this framework, I will update the manual and continue to develop and maintain the core part (i.e. ooc-core) which is the only usable and required part for serious OOPC. The compagnion library (i.e. ooc-std) is incomplete and untested, but it could be used as a start to develop a useful library on top of OOC-2.0.

Acknowledgment: I would like to thanks Ovidiu Achim who wrote the objects fast  allocator, the testsuite of ooc-core, most of the code you may find in the ooc-std library and did the port of JUnit. And Florent Georges who did a partial port of JDBC (code in ooc-db).


Laurent Deniau, last change 2007-03-26