comp.lang.ada
 help / color / mirror / Atom feed
From: Ole-Hjalmar Kristensen <ole-hjalmar.kristensen@substitute_employer_here.com>
Subject: Re: Ada access vs C/C++ pointers and references
Date: 20 Aug 2004 09:52:54 +0200
Date: 2004-08-20T07:52:55+00:00	[thread overview]
Message-ID: <wvbr657egsa1.fsf@sun.com> (raw)
In-Reply-To: b47de02.0408190733.558c97ba@posting.google.com

>>>>> "KHD" == Keith H Duggar <duggar@mit.edu> 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.



  parent reply	other threads:[~2004-08-20  7:52 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-08-18 22:27 Ada access vs C/C++ pointers and references Keith H Duggar
2004-08-19  0:21 ` Nick Roberts
2004-08-19 11:42   ` Marin David Condic
2004-08-19  0:29 ` Jim Rogers
2004-08-19  5:19 ` Ludovic Brenta
2004-08-19  6:21   ` Martin Dowie
2004-08-19 11:55     ` Marin David Condic
2004-08-19 18:01     ` Ludovic Brenta
2004-08-19  7:19   ` j
2004-08-19  7:42     ` Martin Dowie
2004-08-19 12:03     ` Marin David Condic
2004-08-19  7:59 ` Ole-Hjalmar Kristensen
2004-08-19 15:33   ` Keith H Duggar
2004-08-19 21:32     ` Ludovic Brenta
2004-08-19 22:18       ` Hyman Rosen
2004-08-20  7:52     ` Ole-Hjalmar Kristensen [this message]
2004-08-19  8:11 ` Dmitry A. Kazakov
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox