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: a07f3367d7,1f8050edb14e8329 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!c34g2000yqn.googlegroups.com!not-for-mail From: =?ISO-8859-1?Q?Hibou57_=28Yannick_Duch=EAne=29?= Newsgroups: comp.lang.ada Subject: Re: Interfacing to C Date: Thu, 24 Dec 2009 02:01:47 -0800 (PST) Organization: http://groups.google.com Message-ID: <53faf11a-df58-45ca-b287-5e1901fcf5a4@c34g2000yqn.googlegroups.com> References: <56284e56-6ac5-427c-8e4f-8a0750527088@z41g2000yqz.googlegroups.com> NNTP-Posting-Host: 77.198.58.127 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1261648907 8295 127.0.0.1 (24 Dec 2009 10:01:47 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 24 Dec 2009 10:01:47 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: c34g2000yqn.googlegroups.com; posting-host=77.198.58.127; posting-account=vrfdLAoAAAAauX_3XwyXEwXCWN3A1l8D User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; fr),gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:8510 Date: 2009-12-24T02:01:47-08:00 List-Id: On 24 d=E9c, 10:46, "RasikaSriniva...@gmail.com" wrote: > I am building an interface to a C library. This library uses structs > like the following: > > typedef struct { > =A0 =A0 x : int ; > =A0 =A0 y : int } =A0MyStruct .... > > 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