comp.lang.ada
 help / color / mirror / Atom feed
* address/access/pointer confusion
@ 2004-10-20 13:56 Hans Van den Eynden
  2004-10-20 16:55 ` Martin Krischik
  2004-10-20 18:51 ` skidmarks
  0 siblings, 2 replies; 6+ messages in thread
From: Hans Van den Eynden @ 2004-10-20 13:56 UTC (permalink / raw)


On http://groups.google.com/groups?hl=nl&lr=&threadm=wvbr657egsa1.fsf%40sun.com&prev=/groups%3Fnum%3D25%26hl%3Dnl%26lr%3D%26group%3Dcomp.lang.ada%26start%3D300
I read

> First, is it correct to say that Ada access types are more
> similar to C++ references (T&) than they are to C/C++
> pointers (T*) ?

No. Ada access types are very similar to C and C++ pointers, and are
typically implemented and used in (almost) exactly the same way.

On http://groups.google.com/groups?hl=nl&lr=&threadm=ss%25ad.1636%246k2.1252%40newsread3.news.pas.earthlink.net&prev=/groups%3Fhl%3Dnl%26lr%3D%26group%3Dcomp.lang.ada
I read

Well an access is not a pointer. System.Address is a pointer.  There
are
functions to convert an access to an Address..An access may contain
additional informations apart from the pointer - like size of the
object
pointed to (for indefinite objects), a reference counter (for access
all or
anonymous access) etc. pp. 

I think that not the same definition??
Can anybody tell me the exact difference between pointer in C++ and
access/address types in Ada???



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: address/access/pointer confusion
  2004-10-20 13:56 address/access/pointer confusion Hans Van den Eynden
@ 2004-10-20 16:55 ` Martin Krischik
  2004-10-20 18:51 ` skidmarks
  1 sibling, 0 replies; 6+ messages in thread
From: Martin Krischik @ 2004-10-20 16:55 UTC (permalink / raw)


Hans Van den Eynden wrote:

> On
>
http://groups.google.com/groups?hl=nl&lr=&threadm=wvbr657egsa1.fsf%40sun.com&prev=/groups%3Fnum%3D25%26hl%3Dnl%26lr%3D%26group%3Dcomp.lang.ada%26start%3D300
> I read
> 
>> First, is it correct to say that Ada access types are more
>> similar to C++ references (T&) than they are to C/C++
>> pointers (T*) ?
> 
> No. Ada access types are very similar to C and C++ pointers, and are
> typically implemented and used in (almost) exactly the same way.
> 
> On
>
http://groups.google.com/groups?hl=nl&lr=&threadm=ss%25ad.1636%246k2.1252%40newsread3.news.pas.earthlink.net&prev=/groups%3Fhl%3Dnl%26lr%3D%26group%3Dcomp.lang.ada
> I read
> 
> Well an access is not a pointer. System.Address is a pointer.  There
> are
> functions to convert an access to an Address..An access may contain
> additional informations apart from the pointer - like size of the
> object
> pointed to (for indefinite objects), a reference counter (for access
> all or
> anonymous access) etc. pp.
> 
> I think that not the same definition??
> Can anybody tell me the exact difference between pointer in C++ and
> access/address types in Ada???


Well an Address is closest to an void*. As it is an address of some object
in memory.

An Access could be several things. Depending on you compiler vendor it could
be normal pointer, or a smart pointer or a handle.

The representation of an access can also be influenced. For example you can
use pragma Convention (C, ...) to make an access C compatible.

Or you can use For A'Storrage_Pool use ... to handle you own memory.

Or you use "access all" to have an access which can point to non heap
memory.

In an Acceess is more then just a pointer or reference.

With Regards.

-- 
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: address/access/pointer confusion
  2004-10-20 13:56 address/access/pointer confusion Hans Van den Eynden
  2004-10-20 16:55 ` Martin Krischik
@ 2004-10-20 18:51 ` skidmarks
  2004-10-20 23:37   ` Georg Bauhaus
  2004-10-21  7:30   ` Jacob Sparre Andersen
  1 sibling, 2 replies; 6+ messages in thread
From: skidmarks @ 2004-10-20 18:51 UTC (permalink / raw)


> I think that not the same definition??
> Can anybody tell me the exact difference between pointer in C++ and
> access/address types in Ada???

(From dialogs on comp.lang.ada):

A C/C++ pointer is an address to an object. The object contains no
compiler provided information concerning it's semantics (and the
application can reinterpret the semantics freely using a cast).

An Ada Access Type is a pointer to an Ada representation of an object.
This representation can be an object, a la C/C++, or a pointer to a
dope vector providing semantic content of the object (and perhaps
other things - I'm not an Ada afficionado). The compiler vendor is
free to choose the interpretation and meaning of an Access Type
subject to the LRM.

Ad Ada Address is a pointer in the same sense as a C/C++ pointer, with
similar operations and interpretation. The proviso is that the Address
can (presumably) point to a dope vector (I need clarification on this)
but may also point to a raw object.

As an example:
    C/C++:     int a[20];
               int *p  = a;
               int *p1 = &a[0];

               // p == p1 == &a[0] the address of the first item in
the
                                   array a (by definition &a == &a(0))

    Ada:       type Arg        is array( 0 .. 19 O of Integer;
               type Arg_Access is access all Arg;
               a  : aliased Arg;
               p  : Arg_Access     := a'Access;
               p1 : System.Address := a(0)'Address;

               -- p /= p1 in general
               -- One representation of 'a' could be:
               -- a  => <<size of a><pointer to space for a>> --> a(0)
               -- p  => points to the 'a' dope vector (above)
               -- p1 => points to the first element of a, a(0)
               -- 
               -- In this case, p1 is equivalent to the C/C++ p, p1,
               --               p  has no C/C++ equivalency

I think I've got it correct. No doubt someone more knowledgeable will
fill in the edges if there are any errors.

art



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: address/access/pointer confusion
  2004-10-20 18:51 ` skidmarks
@ 2004-10-20 23:37   ` Georg Bauhaus
  2004-10-21  7:30   ` Jacob Sparre Andersen
  1 sibling, 0 replies; 6+ messages in thread
From: Georg Bauhaus @ 2004-10-20 23:37 UTC (permalink / raw)


skidmarks <aschwarz@acm.org> wrote:


:               p1 : System.Address := a(0)'Address;
not necessarily, I think.

And you also need to declare that a's components may be aliased,
using the same keyword "aliased" as you did for a, for the Integers in a.

When you compare C pointers to Ada arrays, the set
of attributes and array operations is largly missing in C.
(They are available in Ada, even for identifiers indirectly
denoting an array, as you have indicated.)

  a'range

for example.


:               -- p /= p1 in general
:               -- One representation of 'a' could be:
:               -- a  => <<size of a><pointer to space for a>> --> a(0)
:               -- p  => points to the 'a' dope vector (above)

AFAIK, dope info cannot always be assumed to be near addressing cells.
I think the GNAT docs, for example, speak about this in the
section on string access, using either fat or thin pointers.


-- Georg



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: address/access/pointer confusion
  2004-10-20 18:51 ` skidmarks
  2004-10-20 23:37   ` Georg Bauhaus
@ 2004-10-21  7:30   ` Jacob Sparre Andersen
  2004-10-22  1:14     ` Jeffrey Carter
  1 sibling, 1 reply; 6+ messages in thread
From: Jacob Sparre Andersen @ 2004-10-21  7:30 UTC (permalink / raw)


<aschwarz@acm.org> wrote:

I don't think there exists a one-to-one mapping between Ada and C
pointer-like types.

> An Ada Address is a pointer in the same sense as a C/C++ pointer,
> with similar operations and interpretation.

Not quite.  I think (Ada) System.Address specifically corresponds to a
(C) void pointer, since System.Address doesn't have a specific type
associated with it, and thus doesn't have the "increment by the size
of the object pointed to" function that non-void pointers have.

Greetings,

Jacob
-- 
"I don't want to gain immortality in my works.
 I want to gain it by not dying."



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: address/access/pointer confusion
  2004-10-21  7:30   ` Jacob Sparre Andersen
@ 2004-10-22  1:14     ` Jeffrey Carter
  0 siblings, 0 replies; 6+ messages in thread
From: Jeffrey Carter @ 2004-10-22  1:14 UTC (permalink / raw)


Jacob Sparre Andersen wrote:

> Not quite.  I think (Ada) System.Address specifically corresponds to a
> (C) void pointer, since System.Address doesn't have a specific type
> associated with it, and thus doesn't have the "increment by the size
> of the object pointed to" function that non-void pointers have.

The Ada equivalent of a C pointer is an access type with convention C. 
For void pointers, I typically use

type Void_Ptr is access all Integer; -- Target doesn't matter
pragma Convention (C, Void_Pointer);

-- 
Jeff Carter
"You cheesy lot of second-hand electric donkey-bottom biters."
Monty Python & the Holy Grail
14




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2004-10-22  1:14 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-20 13:56 address/access/pointer confusion Hans Van den Eynden
2004-10-20 16:55 ` Martin Krischik
2004-10-20 18:51 ` skidmarks
2004-10-20 23:37   ` Georg Bauhaus
2004-10-21  7:30   ` Jacob Sparre Andersen
2004-10-22  1:14     ` Jeffrey Carter

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