Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Object Oriented pattern in C? [duplicate]

Tags:

c

oop

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?

like image 363
horseyguy Avatar asked Dec 04 '22 14:12

horseyguy


2 Answers

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

  • Object Oriented Programming with C - A very thorough treatment of the subject.
  • Phil's guide to object-oriented C - This is a rather simplistic approach to the subject, imo.
  • GObject Reference Manual - GObject is used heavily throughout Gnome and GTK+ applications (mostly on Linux) and therefore provides a thorough example of Object Oriented C in the real world.
like image 128
jsight Avatar answered Dec 06 '22 05:12

jsight


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.

like image 29
Steve Gilham Avatar answered Dec 06 '22 04:12

Steve Gilham