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,c370342fe303517b X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!homer!news.glorb.com!news-spur1.glorb.com!news.glorb.com!wns13feed!worldnet.att.net!attbi_s22.POSTED!53ab2750!not-for-mail From: "Jeffrey R. Carter" User-Agent: Thunderbird 1.5.0.9 (Windows/20061207) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: C Interface example References: <1170516037.435847.326440@p10g2000cwp.googlegroups.com> In-Reply-To: <1170516037.435847.326440@p10g2000cwp.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: NNTP-Posting-Host: 12.201.97.213 X-Complaints-To: abuse@mchsi.com X-Trace: attbi_s22 1170535962 12.201.97.213 (Sat, 03 Feb 2007 20:52:42 GMT) NNTP-Posting-Date: Sat, 03 Feb 2007 20:52:42 GMT Organization: AT&T ASP.att.net Date: Sat, 03 Feb 2007 20:52:42 GMT Xref: g2news2.google.com comp.lang.ada:8901 Date: 2007-02-03T20:52:42+00:00 List-Id: artifact.one@googlemail.com wrote: > float *vec_add(float *va, float *vb, unsigned int ne) > { > unsigned int ind; > for (ind = 0; ind < ne; ++ind) > va[ind] += vb[ind]; > return va; > } > > Now what would be the most simple and portable way to write > a vector,ads and vector.adb file? (Specification and body, in case > those are compiler-specific filenames, I'm not intimate with the > Ada language spec yet!). I just don't have a good enough > understanding of the language to see how it all fits together > yet and I usually learn by example. I think all of the examples posted so far have some minor problem or other in meeting your goal of portability. I'd suggest with Interfaces.C; package C_Vectors is type Vector is array (Positive range <>) of Interfaces.C.C_Float; pragma Convention (C, Vector); procedure Add (To : in out Vector; Using : in Vector; Length : in Natural); end C_Vectors; package body C_Vectors is procedure Add (To : in out Vector; Using : in Vector; Length : in Natural) is type C_Ptr is access all Interfaces.C.C_Float; pragma Convention (C, C_Ptr); function C_Add (To : Vector; Using : Vector: Length : Interfaces.C.Unsigned) return C_Ptr; pragma Import (C, C_Add, "vec_addNf"); Result : C_Ptr; begin -- Add Result := C_Add (To, Using, Interfaces.C.Unsigned (Length) ); end Add; end C_Vectors; -- Jeff Carter "C++ is like jamming a helicopter inside a Miata and expecting some sort of improvement." Drew Olbrich 51