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!news1.google.com!news.glorb.com!newsfeed1.ip.tiscali.net!tiscali!transit1.news.tiscali.nl!dreader2.news.tiscali.nl!not-for-mail Newsgroups: comp.lang.ada Subject: Re: Ada access vs C/C++ pointers and references References: From: Ludovic Brenta Date: Thu, 19 Aug 2004 23:32:02 +0200 Message-ID: <87fz6irezx.fsf@insalien.org> User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) Cancel-Lock: sha1:n/SsIm6B4z9XkC5eu81oR7SezMU= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Organization: Tiscali bv NNTP-Posting-Date: 19 Aug 2004 23:32:41 CEST NNTP-Posting-Host: 83.134.237.203 X-Trace: 1092951161 dreader2.news.tiscali.nl 62391 83.134.237.203:35879 X-Complaints-To: abuse@tiscali.nl Xref: g2news1.google.com comp.lang.ada:2876 Date: 2004-08-19T23:32:41+02:00 List-Id: 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. > > Originally in C "x->" was shorthand for "(*x)." > > However, in C++ "->" serves the very useful purpose of > (via operator overloading) allowing smart pointer types > and iterator types to have the same semantics of raw > pointers in addition to allowing the usual member access. > Thus > > iterator->f() //access f() in object "pointed" to > smart_pointer->f() //access f() in object "pointed" to > iterator.f() //access f() in iterator object > smart_pointer.f() //access f() in smart pointer object This is the kind of thing that is really very appealing to gurus, but after trying to use them for a while I turned away from C++. If one overloads "new", "delete", "->" and "()", one quickly gets into a maintenance nightmare. For example, suppose I have: smart_pointer* p; Then you can easily find yourself writing: p->f(); // [1] (*p).f(); // [2] p.f(); // illegal, I think (*p)->f(); // [3] And I'm not even sure anymore what each of these mean :) > Otherwise, if the pointed to type had a function named f and the > iterator had a function named f which function would interator.f() > access? > > How is this resolved in Ada? Resoved? You mean, like a problem? Ada does not have a problem in this respect, and so does not need to resolve it. On the left of ".", you have either a record, or an access to a record. On the right of ".", you have one of the members of the record, or "all" to mean the entire record. Ada does not allow you to override the meaning of ".", so you always know exactly what you're doing. procedure Proc is type Object is ...; type Object_Access is access all Object; procedure P (O : in out Object) is separate; type Iterator is record Pointed_To : Object_Access; end record; procedure P (I : in out Object) is separate; type Iterator_Access is access Iterator; It : Iterator_Access is new Iterator (Pointed_To => new Object); begin P (It.all); P (It.Pointed_To.all); -- implicit dereference of It P (It.all.Pointed_To.all); -- explicit dereference of It end Proc; As you can see, none of the calls is ambiguous. -- Ludovic Brenta.