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,e940dc253695e939 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!m36g2000hse.googlegroups.com!not-for-mail From: Ludovic Brenta Newsgroups: comp.lang.ada Subject: Re: Pointer Date: Mon, 19 May 2008 03:34:19 -0700 (PDT) Organization: http://groups.google.com Message-ID: <93f38d4d-b34f-4858-a818-7dc5d65cbb0b@m36g2000hse.googlegroups.com> References: <2rjq6ys3fang$.1ir8q3892mjwo$.dlg@40tude.net> <483152DC.4040607@gmail.com> NNTP-Posting-Host: 153.98.68.197 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1211193260 12269 127.0.0.1 (19 May 2008 10:34:20 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 19 May 2008 10:34:20 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: m36g2000hse.googlegroups.com; posting-host=153.98.68.197; posting-account=pcLQNgkAAAD9TrXkhkIgiY6-MDtJjIlC User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.3) Gecko/20040924,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:234 Date: 2008-05-19T03:34:19-07:00 List-Id: S=E9bastien wrote: > > Suggesting, n is returned from the C program: > > > > with Interfaces.C; use Interfaces.C; > > with Interfaces.C.Strings; use Interfaces.C.Strings; > > > > function Get_It return String is > > procedure Internal (N : out size_t; Data : out chars_ptr); > > pragma Import (C, Internal, ""); > > Data : chars_ptr; > > N : size_t; > > begin > > Internal (Data); > > return Value (N, Data); > > end Get_It; > > Yes it's exaclty what I did ... and it's exaclty what I would like to > avoid :-) Actually, I was looking for a pure Ada solution. > I think there is a way using an unchecked type conversion, but how to be > sure of the size of the System.Address? procedure To_String (Pointer : in System.Address; Length : in Natural) return String is Result : String (1 .. Length); for Result'Address use Pointer; pragma Import (Ada, Result); -- suppress default initialization begin return Result; end To_String; But Dmitryi's solution is safer, of course. HTH -- Ludovic Brenta.