Sign up ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

Quite often C is the primary platform for the development. And when things are large scale, I have seen partitioning of the system as different objects is quite a natural thing. Some or many of the object orientated analysis and design principles are used here very well.

This is not a debate question about whether or not C is a good candidate for object oriented programming or not. This is also NOT a question how to do OO in C. You can refer to this question and there are probably many such citations.

As far as I am concerned, I have learned some of this things while working with many open source and commercial projects. (libjpeg, ffmpeg, Gstreamer which is based on GObject).

I can probably extend a few references that explains some of these concepts such as

  1. Event Helix article
  2. Linux Mag article
  3. one of my answers which links Schreiner's reference
    Schreiner is definitely one of the only reference I know. However, there are few things/ approaches that I don't quite like about it. At times, this books gears more towards theoretically being closure to OO_ness_ rather than being useful. But, definitely, this is perhaps the most giant leap of all reference I have found.

Unfortunately, when we induct younger folks, it seems too hard to make them learn all of it the hard way. Usually, when we say it's C, a general reaction is to throw away all of the "Object thinking".

Looking for help extending above references from those who have been in the similar areas of work.

Are there any good formal literature that explains how Object thinking can be made to use while you are working in C?

I have seen tons of book on general "object oriented paradigms" but they all focus on advanced languages mostly not in C. You see most C books - but most focus only on the syntax and the obfuscated corners of C and that's it. There are hardly ANY good reference, specially books or any systematic (I mean formal) literature on how to apply OO in C. This is very surprising given that so many large scale open source projects use C which are truly using this very well; but we hardly see any good formal literature on this subject.

share|improve this question

closed as not constructive by Mark Trapp, World Engineer, Caleb, Thomas Owens Oct 16 '12 at 9:34

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

Why close flags? What can I edit to save this question? –  Dipan Mehta Oct 16 '12 at 7:48
I imagine people are reading the "If you can imagine an entire book that answers your question, you’re asking too much." sentence in the FAQ. Personally I think this is a good question to leave open, just pointing out where people could have an issue. –  user4051 Oct 16 '12 at 8:01
Questions should tend to focus on problems that you are having, not broad requests for literature. Simply searching for "object oriented C" on Google yields a large number of results including books, websites, and papers. After reading some of these, what don't you understand? What problem can't you solve? –  Thomas Owens Oct 16 '12 at 9:36
@GrahamLee I am not really asking anyone to detail out and write a book here. I am only asking for cannonical or trustworthy references. So may be I should edit the question to reflect it more specifically? –  Dipan Mehta Oct 16 '12 at 13:16
My request : –  Dipan Mehta Oct 16 '12 at 13:17

3 Answers 3

Axel-Tobias Schreiner provides a solidly written (though not type safe) guide to C programming in ANSI C89 - Object-oriented Programming with ANSI-C:

...We are simply going to use ANSI-C to discover how object-oriented programming is done, what its techniques are, why they help us solve bigger problems, and how we harness generality and program to catch mistakes earlier. Along the way we encounter all the jargon — classes, inheritance, instances, linkage, methods, objects, polymorphisms, and more — but we take it out of the realm of magic and see how it translates into the things we have known and done all along.

I had fun discovering that ANSI-C is a full-scale object-oriented language. To share this fun you need to be reasonably fluent in ANSI-C to begin with — feeling comfortable with structures, pointers, prototypes, and function pointers is a must...

The first six chapters develop the foundations of object-oriented programming with ANSI-C. We start with a careful information hiding technique for abstract data types, add generic functions based on dynamic linkage and inherit code by judicious lengthening of structures. Finally, we put it all together in a class hierarchy that makes code much easier to maintain...

Object-oriented programming with ANSI-C requires a fair amount of immutable code — names may change but not the structures. Therefore, in chapter seven we build a small preprocessor to create the boilerplate required...

In chapter eight we add dynamic type checking to catch our mistakes earlier on. In chapter nine we arrange for automatic initialization to prevent another class of bugs. Chapter ten introduces delegates and shows how classes and callback functions cooperate to simplify, for example, the constant chore of producing standard main programs. More chapters are concerned with plugging memory leaks by using class methods, storing and loading structured data with a coherent strategy, and disciplined error recovery through a system of nested exception handlers...

Finally, in the last chapter we leave the confines of ANSI-C and implement the obligatory mouse-operated calculator, first for curses and then for the X Window System. This example neatly demonstrates how elegantly we can design and implement using objects and classes, even if we have to cope with the idiosyncrasies of foreign libraries and class hierarchies...

There doesn't seem to be loads out there for more recent standards though.

share|improve this answer
I have trouble taking someone who claims ANSI-C is a "full-scale object-oriented language" seriously, as opposed to "a language I can manage to do OOP with". –  Andres F. Oct 16 '12 at 12:38
@AndresF. are you "reasonably fluent in ANSI-C to begin with — feeling comfortable with structures, pointers, prototypes, and function pointers"? As for the book author, as far as I can tell this guy translated to German such books as K&R and UNIX Programming Environment by Kernighan and Pike –  gnat Oct 16 '12 at 12:58
@gnat I was, though I don't code in C anymore. Let me rephrase: I do not doubt the guy knows his stuff, and the article is clever, but C is not an object-oriented language, period. This isn't really debatable, unless you want to argue assembly is OOP, too. "X-oriented language" != "X can be done with it". So my toned-down assertion is: "I can't take this particular assertion seriously". –  Andres F. Oct 16 '12 at 13:08
+1. This is definitely one of the only reference I know. However, there are few things/ approaches that I don't quite like about it. At times, this books gears more towards theoretically being closure to OO_ness_ rather than being useful. But, definitely, this is perhaps the most giant leap of all reference I have found. –  Dipan Mehta Oct 16 '12 at 13:29

I don't have a theoretical reference, but the Gnome project has a well-known implementation. Check out GObject Reference Manual. GLib Object System is an object-oriented framework built on top of plain old C.

share|improve this answer
GObject is lovely! –  Dipan Mehta Oct 16 '12 at 13:30

The Objective-C language started out as a preprocessor for C that makes use of a message dispatch library. As such, Object-Oriented Programming: An Evolutionary Approach is a good resource for doing OO in C: both in describing the implementation of Objective-C and the motivation for adding OOP to the language. It's long out of print, though.

share|improve this answer
+1. This is something I was searching for - alas, I guess as you said if the book is out of publication, I might not be able to get hold of it. If you have any way to access, let me know. –  Dipan Mehta Oct 16 '12 at 13:22
It's quite easy to find second hand copies. –  user4051 Oct 17 '12 at 17:43

Not the answer you're looking for? Browse other questions tagged or ask your own question.