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,FREEMAIL_FROM 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!postnews.google.com!p10g2000cwp.googlegroups.com!not-for-mail From: artifact.one@googlemail.com Newsgroups: comp.lang.ada Subject: Re: C Interface example Date: 3 Feb 2007 12:57:48 -0800 Organization: http://groups.google.com Message-ID: <1170536268.531049.70610@p10g2000cwp.googlegroups.com> References: <1170516037.435847.326440@p10g2000cwp.googlegroups.com> NNTP-Posting-Host: 81.179.242.178 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1170536278 11777 127.0.0.1 (3 Feb 2007 20:57:58 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 3 Feb 2007 20:57:58 +0000 (UTC) In-Reply-To: User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1) Gecko/20060601 Firefox/2.0 (Ubuntu-edgy),gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: p10g2000cwp.googlegroups.com; posting-host=81.179.242.178; posting-account=3t6ROQ0AAABpbovmj4Qol-vmGur4qb-2 Xref: g2news2.google.com comp.lang.ada:8902 Date: 2007-02-03T12:57:48-08:00 List-Id: On Feb 3, 8:52 pm, "Jeffrey R. Carter" wrote: > artifact....@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; > Hi. This is compiler-agnostic, yes? thanks, MC