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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no 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-7-bit Path: g2news1.google.com!postnews.google.com!d10g2000yqh.googlegroups.com!not-for-mail From: "RasikaSrinivasan@gmail.com" Newsgroups: comp.lang.ada Subject: Re: Interfacing to C Date: Thu, 24 Dec 2009 06:26:34 -0800 (PST) Organization: http://groups.google.com Message-ID: <16195036-2c2a-4c2f-b579-d063650e7e02@d10g2000yqh.googlegroups.com> References: <56284e56-6ac5-427c-8e4f-8a0750527088@z41g2000yqz.googlegroups.com> <4b335ff9$0$6287$4f793bc4@news.tdc.fi> NNTP-Posting-Host: 209.104.243.242 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1261664794 2269 127.0.0.1 (24 Dec 2009 14:26:34 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 24 Dec 2009 14:26:34 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: d10g2000yqh.googlegroups.com; posting-host=209.104.243.242; posting-account=mZyFSQoAAABfOmklsh1d8TPbS2LncUKl User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4 GTB6 GTBA,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:8514 Date: 2009-12-24T06:26:34-08:00 List-Id: On Dec 24, 7:34 am, Niklas Holsti 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