From: artifact.one@googlemail.com
Subject: Re: C Interface example
Date: 3 Feb 2007 09:39:46 -0800
Date: 2007-02-03T09:39:46-08:00 [thread overview]
Message-ID: <1170524386.559414.28960@j27g2000cwj.googlegroups.com> (raw)
In-Reply-To: <87irejmd3v.fsf@ludovic-brenta.org>
On Feb 3, 4:15 pm, Ludovic Brenta <ludo...@ludovic-brenta.org> 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
next prev parent reply other threads:[~2007-02-03 17:39 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-03 15:20 C Interface example artifact.one
2007-02-03 16:15 ` Ludovic Brenta
2007-02-03 17:15 ` Simon Wright
2007-02-03 19:43 ` Ludovic Brenta
2007-02-03 17:39 ` artifact.one [this message]
2007-02-04 14:34 ` Stephen Leake
2007-02-03 16:19 ` Cesar Rabak
2007-02-03 17:40 ` artifact.one
2007-02-03 19:59 ` Cesar Rabak
2007-02-03 17:48 ` Gautier
2007-02-03 18:09 ` artifact.one
2007-02-03 19:17 ` Georg Bauhaus
2007-02-03 19:53 ` artifact.one
2007-02-03 20:02 ` Gautier
2007-02-03 21:36 ` Georg Bauhaus
2007-02-03 19:48 ` tmoran
2007-02-03 19:55 ` artifact.one
2007-02-04 14:37 ` Stephen Leake
2007-02-03 20:42 ` Pascal Obry
2007-02-03 20:52 ` Jeffrey R. Carter
2007-02-03 20:57 ` artifact.one
2007-02-04 4:05 ` Jeffrey R. Carter
2007-02-04 11:52 ` Simon Wright
2007-02-04 20:59 ` Jeffrey R. Carter
2007-02-05 8:56 ` Maciej Sobczak
2007-02-05 18:12 ` Jeffrey R. Carter
2007-02-06 1:48 ` Randy Brukardt
2007-02-06 8:20 ` Maciej Sobczak
2007-02-06 19:18 ` Jeffrey R. Carter
2007-02-04 14:32 ` Stephen Leake
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox