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 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!news2.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nx01.iad01.newshosting.com!newshosting.com!198.186.190.251.MISMATCH!news-out.readnews.com!transit4.readnews.com!panix!bloom-beacon.mit.edu!newsswitch.lcs.mit.edu!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Interfacing to C Date: Thu, 31 Dec 2009 18:18:34 -0500 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <56284e56-6ac5-427c-8e4f-8a0750527088@z41g2000yqz.googlegroups.com> <53faf11a-df58-45ca-b287-5e1901fcf5a4@c34g2000yqn.googlegroups.com> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: pcls6.std.com 1262301504 29381 192.74.137.71 (31 Dec 2009 23:18:24 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Thu, 31 Dec 2009 23:18:24 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:9BaCP5E8bbXw95kRGGA8/XGmp9M= Xref: g2news1.google.com comp.lang.ada:8566 Date: 2009-12-31T18:18:34-05:00 List-Id: Keith Thompson writes: > "Hibou57 (Yannick Duch�ne)" writes: >> On 24 d�c, 10:46, "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 .... > > (The correct syntax is: > typedef struct { > int x; > int y; > } MyStruct; > ) Right. >>> While passing variables of this type to functions, the convention in C >>> is to pass by value (best of my knowledge). > > Yes. In fact, C doesn't have pass by reference as a language feature; > *all* function arguments are passed by value. > > For structs, it's very common in C to do the equivalent of > pass-by-reference, by explicitly passing the address of the struct > object. This is partly because very old versions of C didn't > support struct parameters. Which version of C (when?) introduced (by-copy) struct params? > I find it a bit odd that Ada imposes a pass-by-pointer convention for > C structs. It was a mistake. Partly my fault. I was thinking that it's common in C to pass struct params by explicitly passing a pointer-to-struct, so Ada should mimic that. Bad idea. By the time we realized the mistake, it was too late to fix (compatibility!), so we invented C_Pass_By_Copy as a workaround. > (No, C arrays aren't passed by reference. C array expressions, in > most contexts, are implicitly converted to pointers; the resulting > pointer can be passed by value.) Yeah. In other words, C arrays aren't passed, period. That's another bad idea, and it's not my fault. ;-) - Bob