[comp.sw.components] OO programming by hand in C

kyleb@tekfdi.FDI.TEK.COM (Kyle Bernard) (08/25/89)

There have been some recent mentions of object oriented programming 'by hand'
in C:

ted@nmsu.edu (Ted Dunning):

> ...
> the best example around is the X11 toolkit.  they do wonderful things
> with oo programming by hand in c. 
> ...

johnson@p.cs.uiuc.edu:

> ...
> However, he proves my point.  Calling a function stored in a structure
> IS run-time binding.  He is just showing how to do object-oriented
> programming in C.  It is fine to do object-oriented programming in
> C, and some people prefer that to using C++.  
> ...

I am interested in pointers to information (books, articles, etc.) concerning
this method of implementing objected oriented designs.  Our development
environment is very much C based and the migration to object based analysis
and design appears difficult enough without adding the problems of setting
up a new implementation environment.

Also, I am very interested in the experiences/impressions of those who are
currently using (or have used) C to implement objected oriented designs.

Thanks,
Kyle.
-- 
uucp:	    tektronix!tekfdi!honda!kyleb
US Mail:    Kyle Bernard, Microwave and RF Instruments, Tektronix, Inc.
	    Box 500  MS 58-072, Beaverton OR 97077
Phone:	    503-627-3522

uucibg@swbatl.UUCP (3929) (09/02/89)

In article <3363@tekfdi.FDI.TEK.COM> kyleb@tekfdi.FDI.TEK.COM (Kyle Bernard) writes:
>There have been some recent mentions of object oriented programming 'by hand'
>in C:
>
>I am interested in pointers to information (books, articles, etc.) concerning
>this method of implementing objected oriented designs.  Our development
>environment is very much C based and the migration to object based analysis
>and design appears difficult enough without adding the problems of setting
>up a new implementation environment.
>
>Also, I am very interested in the experiences/impressions of those who are
>currently using (or have used) C to implement objected oriented designs.
>
>Thanks,
>Kyle.

A couple of points:

1) It's fairly simple to get encapsulation by doing something like:

typedef struct _foo {
	...
	int	(*add)();
	...
} *FOO;

You can then invoke the 'add' function for a given 'object' by dereferencing
the pointer and calling the function.  This, I believe, is what was referred
to in a previous posting.  This is very nice and now that I've been using
encapsulation for a while I would never go back.  But personally I find that
inheritance is an even bigger plus, since it is what saves me typing (and
therefore mega-time, even though I am a fairly fast touch typist).


2) This is perhaps somewhat off the subject but...

I've recently implemented a somewhat brain-dead objects-a-la-Smalltalk front end
translator for C using 'nawk' (the new 'awk'), some shell scripts, and some
rather abusive uses of the C preprocessor and macros.  It is rather fragile (if
your input isn't just as the translator wants it to be, it throws a tantrum),
but other than that :) it is fairly nice.  If there is interest, I'd be
willing to discuss how this was done (then again, everyone has probably had
their fill of 'how I created my own OO extenstions to C' by now... :-).

Thanks,
--------------------------------------------------------------------------------
Brian R. Gilstrap    ...!{ {killer,bellcore}!texbell, uunet }!swbatl!uucibg
One Bell Center      +----------------------------------------------------------
Rm 17-G-4            | "Winnie-the-Pooh read the two notices very carefully,
St. Louis, MO 63101  | first from left to right, and afterwards, in case he had
(314) 235-3929       | missed some of it, from right to left."   -- A. A. Milne
--------------------------------------------------------------------------------
Disclaimer:
Me, speak for my company?  You must be joking.  I'm just speaking my mind.