Re: Interfacing with C - pointer problem
- From: "Adam Beneschan" <adam@xxxxxxxxxx>
- Date: 31 Jan 2007 10:10:51 -0800
On Jan 30, 1:10 pm, tmo...@xxxxxxx wrote:
type LPSTR is access all String;
This does not work correct. What I found is, that data'Address is 32
bit and LPSTR is 64 bit.
Because LPSTR points to a dynamic size string and thus needs to
carry along bounds information. A C LPSTR does not point to a dynamic
string, but instead points to a single character - the first in the
string. So the match is
type LPSTR is access Interfaces.C.Char;
procedure C_Func (x : LPSTR); -- expects an address (C-pointer, 32-bit)
and then
data : Interfaces.C.char_array := Interfaces.C.To_C("ABC");
and
C_Func (data(data'first)'unchecked_access);
Or perhaps better:
procedure C_Func (x : Interfaces.C.Strings.chars_ptr);
data : aliased Interfaces.C.char_array := Interfaces.C.To_C
("ABC");
C_Func (Interfaces.C.Strings.To_Chars_Ptr (data'unchecked_access));
May as well use the stuff Ada provides for this exact purpose.
-- Adam
.
- References:
- Interfacing with C - pointer problem
- From: Gerd
- Re: Interfacing with C - pointer problem
- From: tmoran
- Interfacing with C - pointer problem
- Prev by Date: Re: Ravenscar - program termination
- Next by Date: Re: Easy question about Character manipulation
- Previous by thread: Re: Interfacing with C - pointer problem
- Next by thread: Reading Float Data from a binary file into ada
- Index(es):
Relevant Pages
|