Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!uunet!tut.cis.ohio-state.edu!zaphod.mps.ohio-state.edu!wuarchive!swbatl!uucibg From: uucibg@swbatl.UUCP (3929) Newsgroups: comp.object Subject: Re: OOP in C Message-ID: <1031@swbatl.UUCP> Date: 12 Dec 89 17:01:38 GMT References: <3356@hydra.Helsinki.FI> <1691@mrsvr.UUCP> Reply-To: uucibg@swbatl.UUCP (Brian Gilstrap - UCI - 5-3929) Organization: Southwestern Bell Tele. Co. - Advanced Technology Lab - St. Louis Lines: 113 In article <1691@mrsvr.UUCP> hallett@gemed.ge.com (Jeffrey A. Hallett (414) 548-5163) writes: >............. Part of my Master's thesis was the design and >implementation of an "object-oriented" "language" that was compilable >under any UNIX-compatible C compiler (and would even compile under >ANSI-compatible compilers). I quote "object-oriented" because it >didn't have all the nicities (it did have dynamic binding of methods >and inheritance at the leaf level, single inheritance, messaging (in a >crude sense) and anonymous creation during loading and storing (a sort >of continuation mechanism, but not a great one)). I quote "language" >because it was really a set of conventions and predefined structures >and macros that could be compiled under cc. > >It wasn't great, but it did allow us to write some fairly large >object-oriented systems using standard C compilers with only minimal >difficulty. > > Jeffrey A. Hallett, PET Software Engineering > GE Medical Systems, W641, PO Box 414, Milwaukee, WI 53201 > (414) 548-5163 : EMAIL - hallett@gemed.ge.com > Est natura hominum novitatis avida I wrote and have been enhancing (and supporting) something similar for our work group for the past 6 months. For those familiar with Objective-C and/or Complete C, this gives you about 100% the functionality that they do but the syntax is definitely not as nice. The system uses a simple front end made up of shell scripts (using sed, egrep, etc) and some C macros. It actually sets up the appropriate data structures as source code so that there is no runtime cost in having the inheritance hierarchy available. This also has the down side of not providing runtime extensibility of objects (something I've been particularly interested in lately). It has: (1) single inheritance (I'm working on MI), (2) dynamic message resolution, (3) IMHO a much easier way of having multiple inheritance heirarchies (which might be handy if you were developing something embedded which couldn't carry around all the weight of the standard inheritance heirarchy). Becuase it's simple shell scripts and such, it is a bit warty. However, I've been toying with the idea of putting it into a Yacc/Bison and Lex/Flex translator. I'm particularly interested in perhaps adding: (1) daemons, (2) more flexible method overriding (e.g. do-after, do-before kinds of things as apparently exist in Lisp OO systems), (3) method overloading by argument and/or return types (would probably be better done with a Yacc/Lex xlator), (4) MI (anyone have pointers to optimization tree searches and or tree transformations that might be applicable?). Of course, my employer likes the results we're getting from using an OO approach, but doesn't want to take the time to properly implement this thing (or any of the possible extentions). Sigh :-(. The syntax for defining a class Foo based on class Bar looks like: @Class Foo : Bar /* Instance variables */ int fred; @InstanceMethods /* Notice the '#' before the name of the method. * Also, Objective-C and Complete C do: * * - struct fred *myMethod: ( int ) arg1 : ( char * ) arg2 : ( float ) arg3; * { * ... * } */ METHOD struct fred *#myMethod( arg1, arg2, arg3 ) int arg1; char *arg2; float arg3; { struct fred *p; int i; /* We have to do 'self->' which Objective-C and Complete-C * implicitely do for us. */ self->fred = arg1; ... /* The others let you do i = [ super value ] */ i = ask( int, super, value, () ); ... /* The others let you do p = [ self myMethod: i : (char *)0 : 3.24 ] */ p = ask( struct fred *, self, myMethod, ( i, (char *) 0, 3.24 ) ); } ... @InstanceMethods ... @End /* class Foo */ Comments, anyone? -------------------------------------------------------------------------------- Brian R. Gilstrap ...!{ texbell, uunet }!swbatl!uucibg OR uucibg@swbatl.UUCP 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.