C (212/257)

From:
Date:21 Feb 2001 at 23:44:17
Subject:Re: Pseudo-OO in C [was includes and stuff]

Hi Ian,

> You can take this one step further and make object oriented libraries
> (yes... in C). You can effectively hide private data internal to your
> library in the following way:

[...]

Yep, tricks like these work well in some situations - and you can take this
a step further still with function pointers. For instance, in a graphics
program I was working on recently, the graphics subsystem was accessed
through a structure like this:

struct DisplayContext
{
void (*Dispose)(struct DisplayContext *dc);
void (*Handle)(struct DisplayContext *dc,long signals);
void (*Update)(struct DisplayContext *dc);
void (*Render)(struct DisplayContext *dc,struct RenderContext *rc);
void (*SetGamme)(struct DisplayContext *dc,float gamma);
long signals;
void *Specifics;
};

The big advantage here is that the program can be made to use any one of the
four drivers (AGA, HAM, CGFX-8 and CGFX-24) simply by calling the
appropriate Create() function.

(Another way of achieving the same thing would have been to use loadable
modules, or shared libraries, but this approach fitted in well with the
design of the rest of the program).

All the best,



Alastair M. Robinson, email:blackfive@fakenhamweb.co.uk

-- You know you've been hacking too long when...
...in non-computer related situation you start thinking that whatever you
are doing, it could be done more easily in a shell script.

------------------------ Yahoo! Groups Sponsor ---------------------~-~>
eGroups is now Yahoo! Groups
Click here for more details
http://us.click.yahoo.com/kWP7PD/pYNCAA/4ihDAA/d8AVlB/TM
---------------------------------------------------------------------_->

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/