tags:

views:

284

answers:

4

Possible Duplicate:
Can you write object oriented code in C?

I am writing a large application in C and have heard that prior to the advent of C++ programmers used to implement the "Object Oriented" pattern in C. My question is what is the usual form this pattern takes? and how would I go about implementing such an OOP pattern in a modern C application?

+1  A: 

I used to simply adopt naming conventions for a structure and associated "methods". Each method would begin with e.g. CANDIDATE_ for a candidate object, and be associated with a typedef CANDIDATE { ... }, and be in a file Candidate.c

Larry Watanabe
+2  A: 

Where a C++ object has methods, object-style 'C' takes a struct full of function pointers. The functions corresponding to a member function have an explicit data argument that takes the place of the implied 'this' pointer.

Subclasses use function-pointer structs of the same type, with different function pointers to indicate overridded methods.

Steve Gilham
+4  A: 

Here are a few helpful links to guides on Object Oriented C:

jsight
+1  A: 

An additional link from someone who wrote several OO frameworks for C.

AProgrammer