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,FREEMAIL_FROM autolearn=ham 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 09:20:06 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!msunews!not-for-mail From: "Chad R. Meiners" Newsgroups: comp.lang.ada Subject: Re: C array to Ada pointer to unconstrained array withoutcopyingmemory Date: Wed, 8 Oct 2003 12:16:34 -0400 Organization: Michigan State University Message-ID: References: NNTP-Posting-Host: arctic.cse.msu.edu X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Xref: archiver1.google.com comp.lang.ada:473 Date: 2003-10-08T12:16:34-04:00 List-Id: "Duncan Sands" wrote in message news:mailman.49.1065604749.25614.comp.lang.ada@ada-france.org... > 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. So do the declare at the library level. -CRM.