Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!cs.utexas.edu!samsung!usc!apple!Apple.COM!lsr From: lsr@Apple.COM (Larry Rosenstein) Newsgroups: comp.sys.mac.programmer Subject: Re: C++ interface to Object Pascal, whyfor? Message-ID: <5162@internal.Apple.COM> Date: 13 Nov 89 19:34:01 GMT References: <934@swbatl.UUCP> Sender: usenet@Apple.COM Organization: Objects-R-Us, Apple Computer, Inc. Lines: 79 In article <934@swbatl.UUCP> uucibg@swbatl.UUCP (3929) writes: > + Object Pascal uses objects a la Smalltalk (methods and dynamic dispatch). > (Side note: does this mean that objects in Object Pascal are weakly > typed?) Objects in Object Pascal are strongly typed. Its dispatching mechanism is closer to that of C++ than it is to Smalltalk. I'm not sure what you mean by "methods and dynamic dispatch" in this context. In Object Pascal, you can write aView.Draw. You can think of this as sending the Draw method to the object referenced by aView. At runtime, the system looks up the Draw method for that object and calls that piece of code. In Smalltalk, you can send a draw message to any object; even ones that don't understand draw. In Object Pascal and C++ the type checking prevents this. > + While it's possible (apparently) to mix-and-match Object Pascal Objects > and C++ objects in the same program, trying to do so within a class or > class heirarchy is going to have significant limitations (which are True. MPW C++ can support several kinds of object representation and dispatching. (1) Standard C++ dispatching, which supports multiple inheritance, pointer-based objects, etc. (2) Object Pascal style dispatching, which includes handle-based objects. (3) You can use handle-based objects with C++ dispatching. (4) CFront 1.2 style dispatching, which uses pointer-based objects, but not multiple inheritance. (The reason for this alternative is that it is more space efficient than the standard dispatching, because it doesn't have to allow for multipl inheritance.) The compiler figures out which run time mechanism to use based on the ancestor of the class. The compiler has the built in classes PascalObject, HandleObject, and SingleObject, corresponding to alternatives 2-4. A class can inherit from at most one of these, which prevents you from mixing different kinds of dispatching. > + It's not possible to involve Object Pascal classes in a multiple inheritance > heirarchy. True. If a C++ object inherits from PascalObject, then it is limited to what Object Pascal can do. (Except, I think that you can use the C++ visibility declarations to make instance variables and method private, since these don't involve the runtime system, but only the compiler.) You can mix different kinds of objects in the same program. So you can write the guts of your program using multiple inheritance, while the objects that inherit from MacApp classes would be limited to Object Pascal semantics. The special builtin classes will probably be useful to Macintosh programmers who aren't using MacApp. For example, it usually is a bad idea to allocate a lot of pointer-based objects, except in special cases. Although you can overload the C++ new and delete operators, it probably makes more sense to use HandleObjects. Also, C++ expands its method calls in line. If you look at the generated code, you will see that a method call takes several 68000 instructions. Object Pascal's dispatching is a bit slower, but each method call takes 4 bytes. If you use the C++ dispatching mechanism, then your code size will increase. So you might want to use PascalObjects to reduce your code size (at a cost in language features). Larry Rosenstein, Apple Computer, Inc. Object Specialist Internet: lsr@Apple.com UUCP: {nsc, sun}!apple!lsr AppleLink: Rosenstein1