Article View: comp.sw.components
Article #59Re: OO programming by hand in C
From: 3929
Date: Fri, 01 Sep 1989 18:23
Date: Fri, 01 Sep 1989 18:23
54 lines
3059 bytes
3059 bytes
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.
Technical Details
Message-ID:
<762@swbatl.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!swbatl!uucibgReferences:
<3363@tekfdi.FDI.TEK.COM>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!swbatl!uucibg From: uucibg@swbatl.UUCP (3929) Newsgroups: comp.sw.components Subject: Re: OO programming by hand in C Keywords: object oriented programming C Message-ID: <762@swbatl.UUCP> Date: 1 Sep 89 18:23:08 GMT References: <3363@tekfdi.FDI.TEK.COM> Reply-To: uucibg@swbatl.UUCP (Brian Gilstrap - UCI - 5-3929) Organization: Southwestern Bell Tele. Co. - Advanced Technology Lab - St. Louis Lines: 54