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-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!s21g2000prm.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Table of pointers question Date: Thu, 24 Sep 2009 07:55:42 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <4abb18bc$0$30225$9b4e6d93@newsspool1.arcor-online.net> 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 1253804143 5554 127.0.0.1 (24 Sep 2009 14:55:43 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 24 Sep 2009 14:55:43 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: s21g2000prm.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:8457 Date: 2009-09-24T07:55:42-07:00 List-Id: On Sep 23, 11:59=A0pm, Georg Bauhaus wrote: > Rob Solomon wrote: > > I am working my way thru Ada As A Second Language by Norman Cohen (c) > > 1996 > > > This confuses me. > > > It is a simple sorting routine that swaps pointers rather than the > > data. =A0Note that the variables are more like Modula-2 syntax as I am > > very comfortable with that. =A0And it is easier to type. > > Has something gone wrong when (I'm guessing here) the > program was rewritten for Ada? =A0The compiler shows some > errors. =A0After correcting these formally, i.e. without thinking, > it confirms Adam's observation, and hints to others: > > Compiling: printdirectory.adb (source file time stamp: 2009-09-24 06:42:5= 0) > > =A0 =A0 25. =A0 EntryList =A0 =A0 =A0 =A0: array (1..MaxEntries) of Direc= toryEntryType; > =A0 =A0 =A0 =A0 =A0 | > =A0 =A0 =A0 =A0 >>> warning: variable "EntryList" is not referenced > > =A0 =A0 33. =A0 =A0 NewEntry.NamePart :=3D To_Bounded_String(Buffer(1..Le= ngth)); > =A0 =A0 =A0 =A0 =A0 =A0 | > =A0 =A0 =A0 =A0 >>> warning: "NewEntry" may be null > > Here, the "correction" was > 1 - =A0END IF; =A0-- semicolon, not colon > ... > 2, 3 - =A0 =A0EntryPointerList(NumberOfEntries) :=3D -- *new* > DirectoryEntry*Pointer*Type'(NewEntry); =A0-- MY QUESTION HERE > > (NewEntry is of a pointer type already.) That's the error. NewEntry should not be a pointer type. The intent appears to be that a record of type DirectoryEntryType is built, and then a copy of it allocated on the heap and the pointer stored in the array. (I'm assuming that's the case; I don't have Cohen's book handy.) So the declaration of NewEntry is wrong. Perhaps that has to do with a misunderstanding of the relationship between pointers and data; but I think it's more likely just a typographical error, made harder to spot by the lack of underscores. -- Adam