From: "RasikaSrinivasan@gmail.com" <rasikasrinivasan@gmail.com>
Subject: Re: Interfacing to C
Date: Thu, 24 Dec 2009 06:26:34 -0800 (PST)
Date: 2009-12-24T06:26:34-08:00 [thread overview]
Message-ID: <16195036-2c2a-4c2f-b579-d063650e7e02@d10g2000yqh.googlegroups.com> (raw)
In-Reply-To: 4b335ff9$0$6287$4f793bc4@news.tdc.fi
On Dec 24, 7:34 am, Niklas Holsti <niklas.hol...@tidorum.invalid>
wrote:
> 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).
>
> Correct, as I understand the C parameter-passing rules.
>
> > 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.
>
> Yes, by default Ada considers records/struct under convention C as
> pass-by-reference (LRM B.3 (69/2)). C programmers often choose to pass
> structs by reference (pointer to struct) and the Ada Convention (C)
> pragma has been defined accordingly. Or so I guess.
>
> > So the question is - how c(an I force Ada (gnat) to pass a record by
> > value?
>
> Use Pragma Convention (C_Pass_By_Copy, MyStruct). See LRM B.3 (60.14/2)
> and LRM B.3 (68.1/2).
>
> --
> Niklas Holsti
> Tidorum Ltd
> niklas holsti tidorum fi
> . @ .
Vadim and Niklas
Thank you so much, srini
next prev parent reply other threads:[~2009-12-24 14:26 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)
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 [this message]
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