From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Interfacing to C
Date: Thu, 31 Dec 2009 18:18:34 -0500
Date: 2009-12-31T18:18:34-05:00 [thread overview]
Message-ID: <wcc1viaag1h.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: lnmy17bybr.fsf@nuthaus.mib.org
Keith Thompson <kst-u@mib.org> writes:
> "Hibou57 (Yannick Duch�ne)" <yannick_duchene@yahoo.fr> writes:
>> 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 ....
>
> (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
next prev parent reply other threads:[~2009-12-31 23:18 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 [this message]
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