comp.lang.ada
 help / color / mirror / Atom feed
From: "Adam Beneschan" <adam@irvine.com>
Subject: Re: Interfacing with C - pointer problem
Date: 31 Jan 2007 10:10:51 -0800
Date: 2007-01-31T10:10:51-08:00	[thread overview]
Message-ID: <1170267048.731810.18900@k78g2000cwa.googlegroups.com> (raw)
In-Reply-To: <aP-dnTYI5YPAKSLYnZ2dnUVZ_oWdnZ2d@comcast.com>

On Jan 30, 1:10 pm, tmo...@acm.org 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




  reply	other threads:[~2007-01-31 18:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-30 14:23 Interfacing with C - pointer problem Gerd
2007-01-30 15:53 ` Frank J. Lhota
2007-01-30 21:10 ` tmoran
2007-01-31 18:10   ` Adam Beneschan [this message]
2007-01-31 23:53     ` Jeffrey R. 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