comp.lang.ada
 help / color / mirror / Atom feed
From: "Hibou57 (Yannick Duchêne)" <yannick_duchene@yahoo.fr>
Subject: Re: Interfacing to C
Date: Thu, 24 Dec 2009 02:01:47 -0800 (PST)
Date: 2009-12-24T02:01:47-08:00	[thread overview]
Message-ID: <53faf11a-df58-45ca-b287-5e1901fcf5a4@c34g2000yqn.googlegroups.com> (raw)
In-Reply-To: 56284e56-6ac5-427c-8e4f-8a0750527088@z41g2000yqz.googlegroups.com

On 24 déc, 10:46, "RasikaSriniva...@gmail.com"
<rasikasriniva...@gmail.com> wrote:
> I am building an interface to a C library. This library uses structs
> like the following:
>
> typedef struct {
>     x : int ;
>     y : int }  MyStruct ....
>
> While passing variables of this type to functions, the convention in C
> is to pass by value (best of my knowledge).
To mine, this is done by reference.
The compiler may apply some optimization on static functions, i.e. the
ones which are not exported, if it does, it should not with public
functions.

> however when I import a function like:
>
> type MyStruct is record ..... end record ;
> pragma Convention(C,MyStruct);
>
> procedure process(var : MyStruct);
> pragma Import(C,process);
>
> It appears that Ada passes the var by reference.
Your Ada compiler apply the C convention, as you require it to do :p

> (Well - I am not able
> to tell for sure - just that modifying the binding as follows :
>
> procedure process(varx : int; vary : int);
> pragma Import(C,process) ;
>
> works and the previous binding did not.
Why would you want to do so ?

Did you checked the function you want to access from Ada really expect
this ?

If it is, then perhaps it does not really use the C convention.


> So the question is - how c(an I force Ada (gnat) to pass a record by
> value?
>
> thanks for pointers, srini
I do not know, I will check about it (I'm mostly sure it is not
possible), unless someone else come with a better answer.

Have a nice day and a Merry Christmas



  reply	other threads:[~2009-12-24 10:01 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-24  9:46 Interfacing to C RasikaSrinivasan@gmail.com
2009-12-24 10:01 ` Hibou57 (Yannick Duchêne) [this message]
2009-12-25  2:07   ` Keith Thompson
2009-12-31 23:18     ` Robert A Duff
2010-01-01 18:02       ` Keith Thompson
2009-12-24 12:34 ` Niklas Holsti
2009-12-24 14:26   ` RasikaSrinivasan@gmail.com
2009-12-28  7:20   ` Hibou57 (Yannick Duchêne)
2009-12-24 12:35 ` Vadim Godunko
  -- strict thread matches above, loose matches on Subject: below --
2005-02-08 18:07 Garry
2005-02-08 18:43 ` Georg Bauhaus
2005-02-08 19:01 ` Ludovic Brenta
2005-02-08 19:27 ` Martin Krischik
2005-02-08 20:50 ` Björn Lundin
2005-02-09  7:27   ` Anders Wirzenius
2005-02-09 18:53     ` Garry
2005-02-09 21:35       ` Björn Lundin
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox