comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Pointer types (I mean access types)
Date: Fri, 10 Jul 2009 17:59:56 -0700 (PDT)
Date: 2009-07-10T17:59:56-07:00	[thread overview]
Message-ID: <e5e24286-b382-439a-98cc-c2127a759828@24g2000yqm.googlegroups.com> (raw)
In-Reply-To: t9lf55t55qh7puub368vnr55pf215d9nmh@4ax.com

On Jul 10, 5:03 pm, Rob Solomon <use...@drrob1-noreply.com> wrote:
> I am trying to understand how pointers work in Ada.  I would like to
> know if I have the correct equivalencies
>
> Assume this declaration:
>   type List_Node;  -- An incomplete type declaration.
>   type List_Node_Access is access List_Node;
>   type List_Node is
>     record
>       Data        : Integer;
>       Next        : List_Node_Access;
>     end record;
>
> Ada                                               Modula-2 (or Pascal)
> --------------------------------             ----------------------
> type Node_Access is access Node; TYPE NodeAccess = POINTER TO Node;
> Start : Node_Access;                      VAR Start : NodeAccess;
> Current := new Node;                    Current := NEW(Node);
> Current := Start;                            Current := Start;
> Current.all := Start.all;                   Current^ := Start^;
> Current.Data := 5;                         Current^.Data := 5;

I don't know Modula-2.  In Pascal, NEW is a procedure, not a function
that returns a value.  But you've got the Ada right.  You can also say
something like

   Current := new Node' (Data => 5, Next => null);

or

   Current := new Node' (Start.all);

to allocate a new Node and set up its value all at the same time.

Also, although .all is the equivalent to Pascal's ^, you can omit it
if it's followed by a record component or array index (or other
things).  So you could have said

   Current.all.Data := 5;

although nobody does.  It's equivalent to

   Current.Data := 5;

Hope this helps a little,

                               -- Adam



  reply	other threads:[~2009-07-11  0:59 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-11  0:03 Pointer types (I mean access types) Rob Solomon
2009-07-11  0:59 ` Adam Beneschan [this message]
2009-07-11  1:23 ` Randy Brukardt
2009-07-11  9:01   ` Hibou57 (Yannick Duchêne)
2009-07-11 19:41 ` anon
2009-07-12  9:03 ` Gautier write-only
replies disabled

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