It's very doable, though C++ is arguably cleaner. Xlib contains a few OO principles, and GTK+ even more. Both are written in ANSI C. And let's not forget the UNIX concept of the file descriptor (which can be a file, device, pipe, or socket)
" are done in the form objectname_action()
, and the first arg
is usually an object
, a la the this pointer
" are done as objectname_new()
, et cetera
. There are relatively ugly
ways to have multiple constructors
that do the same thing but take different args
, like the GTK+
One way to achieve OO is to typedef each object type as int (a descriptor) and have some sort of global data structure for each type of object, to use as your private data. For inheritance, you just make a new typedef, global data structure, and set of methods. And since all objects are really an int, all existing methods should work on an inherited object.
Another way for an object model in ANSI C is based on struct pointers. This is somewhat harder to do with inheritance, but GTK+ manages.
Either way, C++
and the like are probably a lot easier