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!j27g2000cwj.googlegroups.com!not-for-mail From: artifact.one@googlemail.com Newsgroups: comp.lang.ada Subject: Re: C Interface example Date: 3 Feb 2007 09:39:46 -0800 Organization: http://groups.google.com Message-ID: <1170524386.559414.28960@j27g2000cwj.googlegroups.com> References: <1170516037.435847.326440@p10g2000cwp.googlegroups.com> <87irejmd3v.fsf@ludovic-brenta.org> NNTP-Posting-Host: 81.179.242.178 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1170524391 16115 127.0.0.1 (3 Feb 2007 17:39:51 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 3 Feb 2007 17:39:51 +0000 (UTC) In-Reply-To: <87irejmd3v.fsf@ludovic-brenta.org> 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: j27g2000cwj.googlegroups.com; posting-host=81.179.242.178; posting-account=3t6ROQ0AAABpbovmj4Qol-vmGur4qb-2 Xref: g2news2.google.com comp.lang.ada:8884 Date: 2007-02-03T09:39:46-08:00 List-Id: On Feb 3, 4:15 pm, Ludovic Brenta wrote: > artifact.one writes: > > #ifndef VECTOR_H > > #define VECTOR_H > > > float *vec_addNf(float *, float *, unsigned int); > > > #endif > > package Vec is > type Array_Of_Floats is array (Natural range <>) of Float; > function Add (VA : access Array_Of_Floats; > VB : in Array_Of_Floats; > Length : in Natural) > return access Array_Of_Floats; -- Ada 2005 required here > pragma Import (C, Add, "vec_addNf"); > end Vec; > > but all calls to Add will have to do something with the value > returned. Looking at the body of vec_addNf, I see that the returned > value is useless, since the caller obviously already knows the address > of VA. Taking advantage of that fact, we can instead declare a > procedure: Yes, the original intent in C was to be able to do this sort of thing: vec_addNf(vec_addNf(va, vb), vec_addNf(vc, vd)); ...which may or may not be possible or desirable in Ada. > > package Vec is > type Array_Of_Floats is array (Natural range <>) of Float; > procedure Add (VA : in out Array_Of_Floats; > VB : in Array_Of_Floats; > Length : in Natural); > pragma Import (C, Add, "vec_addNf"); > end Vec; > > HTH > > -- > Ludovic Brenta. Thanks, that makes things a bit clearer. I'll go with the procedure definition over the function. Mc