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-7-bit X-Google-Thread: 103376,35ee0472de38e833 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2000-12-13 15:10:52 PST Path: supernews.google.com!sn-xit-02!supernews.com!newsfeed.online.be!feed.cgocable.net!xfer13.netnews.com!netnews.com!howland.erols.net!cyclone2.usenetserver.com!news-out.usenetserver.com!newsfeed2.earthlink.net!newsfeed.earthlink.net!newsmaster1.prod.itd.earthlink.net!newsread2.prod.itd.earthlink.net.POSTED!not-for-mail Message-ID: <3A37F5FE.E6E2CBB4@acm.org> From: Jeff Carter X-Mailer: Mozilla 4.7 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Variable length raw-byte data References: <00d101c0651c$24e3ea60$f8ffa8c0@dbdell2000> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Wed, 13 Dec 2000 23:10:46 GMT NNTP-Posting-Host: 199.174.148.24 X-Complaints-To: abuse@earthlink.net X-Trace: newsread2.prod.itd.earthlink.net 976749046 199.174.148.24 (Wed, 13 Dec 2000 15:10:46 PST) NNTP-Posting-Date: Wed, 13 Dec 2000 15:10:46 PST Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: supernews.google.com comp.lang.ada:3101 Date: 2000-12-13T23:10:46+00:00 List-Id: David Botton wrote: > > Since Byte_List is unconstrained is there not a potential for problem here > with additional data associated with the type for bounds? > > > type Byte_List is array (Positive range <>) of Unsigned_8; This shouldn't cause a problem, because in Thing : Byte_List (1 .. Length); for Thing'Address use Pointer; Thing'Address is defined to be the address of Thing (Thing'First). If the compiler needs to store any additional information, it has to put that information elsewhere. > > Would this be a better solution: > > C_Thing (Length, Pointer) > > declare > type Byte_List is array (1 .. Length) of Unsigned_8; > Thing : Byte_List; > for Thing'Address use Pointer; > > begin > ... > end; This is certainly OK, too. > > I frequently code the above as: > > C_Thing (Length, Pointer) > > declare > type Byte_List is array (1 .. Length) of Unsigned_8; > type Pointer_To_Byte_List is access all Byte_List; > > function To_Pointer_To_Byte_List is > new Ada.Unchecked_Conversion (System.Address, Pointer_To_Byte_List); > > Thing : Pointer_To_Byte_List := To_Pointer_To_Byte_List > (Pointer'Address); > begin > ... > end; > > Is there a reason that using the for Thing'Address would be a better > solution then the second method? Yes, the second method is not portable. While Unchecked_Conversion between System.Address and an access type may work with some compilers, it definitely does NOT work with all compilers. Since you have a constrained type here, you could use System.Address_To_Access_Conversions to obtain a valid access value, but why add the added baggage of access-type semantics when you can make Thing a Byte_List? -- Jeff Carter "You tiny-brained wipers of other people's bottoms!" Monty Python & the Holy Grail