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,efac8f93bb1bec0a X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!k78g2000cwa.googlegroups.com!not-for-mail From: "Adam Beneschan" Newsgroups: comp.lang.ada Subject: Re: Interfacing with C - pointer problem Date: 31 Jan 2007 10:10:51 -0800 Organization: http://groups.google.com Message-ID: <1170267048.731810.18900@k78g2000cwa.googlegroups.com> References: <1170167017.790966.225850@v45g2000cwv.googlegroups.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1170267057 23962 127.0.0.1 (31 Jan 2007 18:10:57 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 31 Jan 2007 18:10:57 +0000 (UTC) In-Reply-To: User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: k78g2000cwa.googlegroups.com; posting-host=66.126.103.122; posting-account=cw1zeQwAAABOY2vF_g6V_9cdsyY_wV9w Xref: g2news2.google.com comp.lang.ada:8779 Date: 2007-01-31T10:10:51-08:00 List-Id: 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