From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,b860b4e8d00468ef X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed-east.nntpserver.com!nntpserver.com!newsfeed1.sea.pnap.net!newsfeed.pnap.net!brmea-news-1.sun.com!news1nwk.sfbay.sun.com!new-usenet.uk.sun.com!not-for-mail From: Ole-Hjalmar Kristensen Newsgroups: comp.lang.ada Subject: Re: Ada access vs C/C++ pointers and references Date: 20 Aug 2004 09:52:54 +0200 Organization: Sun Microsystems Message-ID: References: NNTP-Posting-Host: khepri06.norway.sun.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: new-usenet.uk.sun.com 1092988375 19408 129.159.112.195 (20 Aug 2004 07:52:55 GMT) X-Complaints-To: usenet@new-usenet.uk.sun.com NNTP-Posting-Date: 20 Aug 2004 07:52:55 GMT User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/21.2 Xref: g2news1.google.com comp.lang.ada:2883 Date: 2004-08-20T07:52:55+00:00 List-Id: >>>>> "KHD" == Keith H Duggar writes: >> No. This is just syntax. "." would have worked just fine for >> dereferencing C/C++ pointers. I suspect the reason for using "->" was >> just to make it more visible that you are using a pointer. KHD> Originally in C "x->" was shorthand for "(*x)." Yes, but strictly speaking, since the compiler *knows* x is a pointer, it could just have two versions of ".", one which works on records, and one which works on pointers. So the shorthand for "(*x)." could just as well have been "x." But i'm completely happy with "->" KHD> However, in C++ "->" serves the very useful purpose of KHD> (via operator overloading) allowing smart pointer types KHD> and iterator types to have the same semantics of raw KHD> pointers in addition to allowing the usual member access. KHD> Thus iterator-> f() //access f() in object "pointed" to smart_pointer-> f() //access f() in object "pointed" to KHD> iterator.f() //access f() in iterator object KHD> smart_pointer.f() //access f() in smart pointer object KHD> Otherwise, if the pointed to type had a function named f KHD> and the iterator had a function named f which function would KHD> interator.f() access? If C++ had allowed dispatching on the return value of a function (operator) you could use a cast to resolve the ambiguity. KHD> How is this resolved in Ada? By not allowing you to overload "." :-) Which means that smart pointers do not look so similar to normal pointers in Ada, of course. KHD> Also, I'm sure there were C compatibility constraints as well. -- C++: The power, elegance and simplicity of a hand grenade.