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=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,4947e94bd021c540 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-10-08 02:21:09 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.stueberl.de!teaser.fr!enst.fr!melchior!cuivre.fr.eu.org!melchior.frmug.org!not-for-mail From: Duncan Sands Newsgroups: comp.lang.ada Subject: Re: C array to Ada pointer to unconstrained array without copyingmemory Date: Wed, 8 Oct 2003 11:20:50 +0200 Organization: Cuivre, Argent, Or Message-ID: References: NNTP-Posting-Host: lovelace.ada-france.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Trace: melchior.cuivre.fr.eu.org 1065604754 35698 80.67.180.195 (8 Oct 2003 09:19:14 GMT) X-Complaints-To: usenet@melchior.cuivre.fr.eu.org NNTP-Posting-Date: Wed, 8 Oct 2003 09:19:14 +0000 (UTC) To: "Chad R. Meiners" , comp.lang.ada@ada-france.org Return-Path: User-Agent: KMail/1.5.1 In-Reply-To: Content-Disposition: inline X-Virus-Scanned: by amavisd-new-20030616-p5 (Debian) at ada-france.org X-BeenThere: comp.lang.ada@ada-france.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Gateway to the comp.lang.ada Usenet newsgroup List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Xref: archiver1.google.com comp.lang.ada:450 Date: 2003-10-08T11:20:50+02:00 On Wednesday 08 October 2003 00:52, Chad R. Meiners wrote: > "Chad R. Meiners" wrote in message > news:blvfo6$q6s$1@msunews.cl.msu.edu... > > > declare > > C_Data_Ptr : Systems.Address := To_Address(My_C_Ptr); > > C_Data_Length : Natural := ...; > > > > type My_Ada_Type_Element is ...; > > type My_Ada_Array is array(Natural range <>) of My_Ada_Type_Element; > > > > subtype My_C_Data_As_An_Ada_Array_Type is > > My_Ada_Array(1..C_Data_Length); > > package My_Converter is new > > Address_To_Access_Conversions(My_C_Data_As_An_Ada_Array_Type); > > C_Data_In_Ada : My_Ada_Array renames > > My_Converter.To_Pointer(C_Data_Ptr).all; > > -- No copying of the array done, but the array dope that you want is > > built from the subtype information. > > begin > > ... > > end; > > I should probably add that you can just get the pointer with > > My_Ada_Array_Ptr : My_Converter.Object_Pointer := > My_Converter.To_Pointer(C_Data_Ptr); > > I believe that this satisfies your needs? Not in the slightest. Once you leave this local block, the pointer is unusable because the array dope, stored as a local variable of the block, will disappear. The data continues to hang around of course. Thanks anyway, Duncan.