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!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail NNTP-Posting-Date: Sat, 03 Feb 2007 13:48:21 -0600 From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: Re: C Interface example References: <1170526166.831811.237660@h3g2000cwc.googlegroups.com> X-Newsreader: Tom's custom newsreader Message-ID: Date: Sat, 03 Feb 2007 13:48:21 -0600 NNTP-Posting-Host: 67.164.83.70 X-Trace: sv3-gxaKuvoqbx4vZdID9SVcbGEaz8jvvgKRaB4lCpggUrxBnuNjaIxaLR3aiHv6Rz69i+iIxqh3Dyc3tJZ!mDspt95lMdvVB6KU/z3jOrrA+fzLpyqaOdo/vrhTPQ+Qrik4GuVQhpXt/xJYb24VisjTM54cTMXw!+C2gHSqkugwFDA== X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.32 Xref: g2news2.google.com comp.lang.ada:8893 Date: 2007-02-03T13:48:21-06:00 List-Id: > float *vec_addNf(float *, float *, unsigned int); > Now what would be the most simple and portable way to write > a vector,ads and vector.adb file? (Specification and body, in case > reading all that just for an example on interfacing... If you want to call an existing C routine, not rewriting it in Ada, then the literal translation of the calling interface is: type p_float is access all interfaces.c.c_float; function vec_addNf(va, vb : in p_float; n : in interfaces.c.unsigned) return p_float; pragma import(C, vec_addNf, "vec_addNf"); -- Note: Do this if you really have a C calling convention. -- If you are running on MS Windows, you probably want "StdCall" -- instead of "C" and then use it like this type vectors is array(interfaces.c.unsigned range <>) of aliased interfaces.c.c_float; va, vb : vectors(1 .. 100); trash : p_float; ... trash := vec_addNf(va(va'first)'unchecked_access, vb(vb'first)'unchecked_access, va'length); If you were going to be doing a lot of complex calls on va, vb, vc, and vd you might want instead N : interfaces.c.unsigned := 123; va_data, vb_data, vc_data, vd_data : vectors(1 .. N); va : constant p_float := va_data(va_data'first)'unchecked_access; vb : constant p_float := vb_data(vb_data'first)'unchecked_access; vc : constant p_float := vc_data(vc_data'first)'unchecked_access; vd : constant p_float := vd_data(vd_data'first)'unchecked_access; so you could write things like trash := vec_addNf(vec_addNf(va,vb,N),vec_addNf(vc,vd,N), N);