elcond@garnet.berkeley.edu (Gregory Dow) (07/22/88)
In article <60865@sun.uucp> landman@sun.UUCP (Howard A. Landman) writes: [description of how single inheritance is achieved through nested #include's] >Gee - this sounds like you can get multiple inheritance just by nesting >2 or more include files. So why "single only"? (Assuming no conflicts.) >Is it because you need to know which SuperClass to pass a message to if the >local Class can't handle it, so the dispatcher would get more complicated? > The SuperClass ordering is one problem (depth-first or breadth-first search), the other is more mundane. Message names are implemented as an enumerated type, which C automatically converts to integer values. The root object class has 3 messages, which get numbered as 0, 1, and 2. If Class A, a child of the root class, has 4 messages, they get numbered 3, 4, 5, and 6. Similarly for a Class B which is also descended from the root class. If a Class X has both A and B as superclasses, it will not know how to handle the message number 4. Message 4 may be a FOO message to Class A, and a BAR message to Class B, but the Class X has no way of knowing which one it is. The C preprocessor converts both FOO and BAR to 4. Can anyone suggest an alternative? I'd love it if I could easily implement the "set" data structure from Pascal in C. Then I could just take the union of the messages of the superclasses of a class. I'd really like to find a clean solution to this problem, because standard C++ doesn't support multiple inheritance either. Gregory Dow ARPA: elcond@garnet.berkeley.edu Chemical Engineering Dept. UUCP: {uwvax, decvax, ihnp4, ...}!ucbvax University of California !elcond%garnet.berkeley.edu Berkeley, CA 94720 BITNET: POLYDOW@UCBCMSA
lsr@Apple.COM (Larry Rosenstein) (07/29/88)
In article <12405@agate.BERKELEY.EDU> elcond@garnet.berkeley.edu (Gregory Dow) writes: > >The SuperClass ordering is one problem (depth-first or breadth-first search), >the other is more mundane. Message names are implemented as an enumerated >type, which C automatically converts to integer values. The root object >class has 3 messages, which get numbered as 0, 1, and 2. If Class A, >a child of the root class, has 4 messages, they get numbered 3, 4, 5, and 6. This is the dispatching scheme we used in the very first implementation of Object Pascal (nee Clascal), and it is used in the single-inheritance C++. It has the virtue of being very fast, because it pre-computes the address of the code for each message understood by a class. The time to call a method is constant. When you make a subclass, the subclass' table starts out as a copy of the superclass' table. You add any new methods onto the end, and replace any entries that are overridden. So even if you override 1 method, you still have to copy the entire superclass table. The current Object Pascal dispatcher minimizes the space by only putting the methods a class actually implements into the table. For info on this, see the December 1986 MacTutor. >Can anyone suggest an alternative? I'd love it if I could easily implement >the "set" data structure from Pascal in C. Then I could just take the >union of the messages of the superclasses of a class. I'd really like >to find a clean solution to this problem, because standard C++ doesn't >support multiple inheritance either. I think Stroustrup had a paper in the C++ Workshop Proceedings on multiple inheritance in C++. AT&T also had the paper in its booth at the last OOPSLA. It retains the constant-time method call feature of C++, with only a little increase in space and complexity. Larry Rosenstein, Object Specialist Apple Computer, Inc. 20525 Mariani Ave, MS 46-B Cupertino, CA 95014 AppleLink:Rosenstein1 domain:lsr@Apple.COM UUCP:{sun,voder,nsc,decwrl}!apple!lsr