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: 103376,c7ba3a3c7efe3bd X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!feeder.news-service.com!weretis.net!feeder4.news.weretis.net!nuzba.szn.dk!news.jacob-sparre.dk!pnx.dk!.POSTED!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Adress => Access: types for unchecked conversion have different sizes Date: Sat, 12 Mar 2011 21:32:08 -0600 Organization: Jacob Sparre Andersen Research & Innovation Message-ID: References: NNTP-Posting-Host: static-69-95-181-76.mad.choiceone.net X-Trace: munin.nbi.dk 1299987136 1108 69.95.181.76 (13 Mar 2011 03:32:16 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Sun, 13 Mar 2011 03:32:16 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Response X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5931 Xref: g2news2.google.com comp.lang.ada:19088 Date: 2011-03-12T21:32:08-06:00 List-Id: "Martin Krischik" wrote in message news:op.vr8kbsndz25lew@macpro-eth1.krischik.com... ... > The code in question is: > > {{{ > declare > subtype Path_String is String (1 .. Filename_Len); > type Path_String_Access is access Path_String; As someone else noted, this is a pool-specific access type. It should never point at anything other than memory created by an allocator. (Janus/Ada actually checks that; you'd get Constraint_Error if you tried to dereference the result of the code below.) If you need to point it at something else, you need to use a general access type (that is, "access all"). > function Address_To_Access is new > Ada.Unchecked_Conversion > (Source => Address, > Target => Path_String_Access); > > Path_Access : constant Path_String_Access := > Address_To_Access (Filename_Addr); > > begin > Last := Filename_Len; > Name (1 .. Last) := Path_Access.all; > end; > }}} ... > And I wonder if some `for Address use` magic would not be more appropriate > here. No, that is a lousy way to handle this sort of problem, as is this code. (This appears to be an old Ada 83 design, completely inappropriate in modern Ada -- and a lousy idea in Ada 83, too.). Ada has package Address_to_Access_Conversions for this sort of problem. (That package also has an annoyance: it declares a new access type for each instance, forcing some extra conversions if you intend to use a type declared elsewhere.) Lastly, access to unconstrained is rarely the right thing in such code; it might work on some compiler some of the time, but will not work in general. (Note that Annex B does not require such things to work for interfacing, and using addresses is very similar to interfacing.) Randy.