Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!ceres.physics.uiowa.edu!news.iastate.edu!sharkey!umich!samsung!olivea!apple!apple.com!russell Newsgroups: comp.lang.c++ Subject: Re: fragmentation of free store (Double indirection) Message-ID: <12960@goofy.Apple.COM> From: russell@apple.com (Russell Williams) Date: 8 Apr 91 15:15:13 GMT Sender: usenet@Apple.COM References: <285@paradim.UUCP> <1986@godzilla.tcs.com> <1398@glinda.ctron.com> <12932@goofy.Apple.COM> <1403@glinda.ctron.com> Organization: Apple Computer Lines: 45 In article <1403@glinda.ctron.com> smith@glinda.ctron.com (Larry Smith) writes: > >First, Apple's MPW C++ and Symantec's Think C for the Mac both implement > >this. In MPW C++, classes derived from HandleObject get automatic double > >indirection. This is even more attractive in C++ than Pascal because > >p^^.field in Pascal becomes (*p)->field or (**p).field in C. > > The *compilers* do no such thing. If you have to type (*p)->field then > you are dereferencing the handle yourself. My point is, it's of scant use > if you have to do it yourself, as the rest of your posting pointed out. > I believe the *compiler* should handle all the ugly details. When I say: Sorry to be unclear. If you declare: class foo : HandleObject { int i;... }; foo *pfoo = new foo; You then refer to fields of pfoo like pfoo->i. My comment in the previous posting referred to the desirability of doing this because of the extra awkwardness of writing the double indirection explicitly in a C-syntax language compared to a Pascal one. That is, if you *don't* use HandleObjects, you have to write (*p)->field or (**p).field. Think & MPW give you the syntactic sugar you want for double indirection. As for making everything double indirect, that's not a good choice, since of course it wouldn't be portable. Many Mac toolbox routines need pointers rather than handles (WindowRecords are pointer and not handle-based, for instance). If the compiler automagically dereferenced handles into pointers for them, it would also have to lock them to keep them from moving during the call. What with callback functions, "hooks" and other nasties, it quickly becomes impossible for the compiler to keep track of what's going on. There are also lots of folks who don't want to pay the overhead for double indirection all the time. As for the difficulties of multiple inheritance and stack allocation, just making all pointers behave that way doesn't make things less difficult; those things must still be done. Making pointers non-linear and larger than long will break lots of software (not to mention being slow), so you don't want to force it on people. By the way, I don't work on MPW C++, so I'm not arguing with you as to why these things should or shouldn't be done. I'm just giving some reasons why they haven't been done.