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: a07f3367d7,bfad7b01b410c9fb X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!24g2000yqm.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Pointer types (I mean access types) Date: Fri, 10 Jul 2009 17:59:56 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1247273996 22886 127.0.0.1 (11 Jul 2009 00:59:56 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 11 Jul 2009 00:59:56 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: 24g2000yqm.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618),gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:6968 Date: 2009-07-10T17:59:56-07:00 List-Id: On Jul 10, 5:03=A0pm, Rob Solomon wrote: > I am trying to understand how pointers work in Ada. =A0I would like to > know if I have the correct equivalencies > > Assume this declaration: > =A0 type List_Node; =A0-- An incomplete type declaration. > =A0 type List_Node_Access is access List_Node; > =A0 type List_Node is > =A0 =A0 record > =A0 =A0 =A0 Data =A0 =A0 =A0 =A0: Integer; > =A0 =A0 =A0 Next =A0 =A0 =A0 =A0: List_Node_Access; > =A0 =A0 end record; > > Ada =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 Modula-2 (or Pascal) > -------------------------------- =A0 =A0 =A0 =A0 =A0 =A0 ----------------= ------ > type Node_Access is access Node; TYPE NodeAccess =3D POINTER TO Node; > Start : Node_Access; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0VAR Start= : NodeAccess; > Current :=3D new Node; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Current := =3D NEW(Node); > Current :=3D Start; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0Current :=3D Start; > Current.all :=3D Start.all; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Current^ = :=3D Start^; > Current.Data :=3D 5; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Curr= ent^.Data :=3D 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 :=3D new Node' (Data =3D> 5, Next =3D> null); or Current :=3D 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 :=3D 5; although nobody does. It's equivalent to Current.Data :=3D 5; Hope this helps a little, -- Adam