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 Date: Sat, 03 Feb 2007 18:48:52 +0100 From: Gautier 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 NNTP-Posting-Host: 83.77.181.84 X-Original-NNTP-Posting-Host: 83.77.181.84 Message-ID: <45c4cae7$1_4@news.bluewin.ch> X-Trace: news.bluewin.ch 1170524903 83.77.181.84 (3 Feb 2007 18:48:23 +0100) Organization: Bluewin AG Complaints-To: abuse@bluewin.ch X-Original-NNTP-Posting-Host: 127.0.0.1 Path: g2news2.google.com!news4.google.com!news3.google.com!news2.volia.net!newsfeed01.sul.t-online.de!newsfeed00.sul.t-online.de!t-online.de!130.59.10.21.MISMATCH!kanaga.switch.ch!irazu.switch.ch!news-zh.switch.ch!switch.ch!news.ip-plus.net!newsfeed.ip-plus.net!news.bluewin.ch!not-for-mail Xref: g2news2.google.com comp.lang.ada:8886 Date: 2007-02-03T18:48:52+01:00 List-Id: artifact.one@googlemail.com: > I'm having a bit of trouble getting my head around calling C code > in Ada. I'll spare you my failed attempts, basically I have this code: > > (vector.h) > > #ifndef VECTOR_H > #define VECTOR_H > > float *vec_addNf(float *, float *, unsigned int); > > #endif > > (vec_add.c) > > #include "vector.h" > > 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. Looking at your code the most simple and portable way will be not to interface at all with C! package Vectors is type Vector is array(Natural range <>) of Float; procedure Add(va: in out Vector; vb: in Vector); end Vectors; package body Vectors is procedure Add(va: in out Vector; vb: in Vector) is begin for i in va'Range loop va(i):= va(i) + vb(i); end loop; end Add; end Vectors; Note that most compilers accept the spec and the body (or more!) in the same file with the name of your choice; GNAT requires vectors.ads and vectors.adb HTH ______________________________________________________________ Gautier -- http://www.mysunrise.ch/users/gdm/index.htm Ada programming -- http://www.mysunrise.ch/users/gdm/gsoft.htm NB: For a direct answer, e-mail address on the Web site!