comp.lang.ada
 help / color / mirror / Atom feed
From: Sébastien <seb.morand@gmail.com>
Subject: Re: Pointer
Date: Mon, 19 May 2008 11:31:57 +0000
Date: 2008-05-19T11:31:57+00:00	[thread overview]
Message-ID: <4831652D.3020507@gmail.com> (raw)
In-Reply-To: 

> 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

Ok, I was not clear enough. Converting char* to String is not an issue, 
I'm using Interfaces.C.String with no problem. My problem is to convert 
all the strings in the char** in string one by one.

Something like this:
CharPtrPtr: System.Address := MyCFunctionReturninCharStarStar;
N: Natural := MYCFunctionTellingMeHowManyStrings;

for i in Natural range 0 .. N loop
    -- Some ada code to convert CharPtrPtr[i] to String
end loop;

Of course I can do somthing like that:

Compile this using
gcc -O2 -g3 -ansi -pedantic -W -Wall -c mybind.c -o mybind.o:

char* get_nth(char** data, unsigned int n) {
   return data[i];
}

Ada binding:
function get_nth(data: System.Address; n: Int) return Char_Ptr;
pragma Import(C, get_nth, "get_nth");

Then:
for i in Natural range 0 .. N loop
    MyString := Interfaces.C.Strings.Value(get_nth(CharPtrPtr, i));
end loop;

I know it's working, but I have to code a C function in order to do 
that, is there a way to replace get_nth by an ada code function?

Hope it's a better explanation ;-)



  reply	other threads:[~2008-05-19 11:31 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-19  9:38 Pointer Sébastien
2008-05-19  9:53 ` Pointer Dmitry A. Kazakov
2008-05-19  9:54   ` Pointer Dmitry A. Kazakov
2008-05-19 10:13   ` Pointer Sébastien
2008-05-19 10:32     ` Pointer Dmitry A. Kazakov
2008-05-19 10:34     ` Pointer Ludovic Brenta
2008-05-19 11:31       ` Sébastien [this message]
2008-05-19 12:09         ` Pointer Ludovic Brenta
2008-05-19 12:09         ` Pointer Dmitry A. Kazakov
2008-05-19 12:47           ` Pointer Sébastien
2008-05-19 16:25         ` Pointer Matthew Heaney
2008-05-19 16:22     ` Pointer Matthew Heaney
2008-05-19 16:17 ` Pointer Matthew Heaney
2008-05-19 17:23   ` Pointer Sébastien
  -- strict thread matches above, loose matches on Subject: below --
2005-08-31 17:02 pointer TC
2005-08-31 18:40 ` pointer Martin Krischik
2005-08-31 18:52 ` pointer Jeffrey Carter
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox