From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Interfacing to C library...
Date: Sun, 3 Nov 2002 16:47:47 GMT
Date: 2002-11-03T16:47:47+00:00 [thread overview]
Message-ID: <wccpttm1txo.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: pan.2002.11.03.00.04.21.535611@jps-nospam.net
"Eric G. Miller" <egm2@jps-nospam.net> writes:
> adaic has the new one, adahome has the old one...
Thank you. I printed out the new version of the AARM (on a double-sided
laser printer!) for my own use a while back, but I had forgotten where I
got it.
> I'm not sure I understand your statement about using access parameters
> versus named access types (I'm still pretty green w.r.t. to Ada)....
Probably because I don't really understand what you're trying to do.
Anyway, I'll try to explain:
type R is record....
type A is access all R;
procedure P(X: A; Y: access R);
A is a "named access type".
X is a "parameter of a named access type".
Y is an "access parameter", which is the same thing as
"a parameter of an anonymous access type".
There are various subtle differences between named and anonymous access
types, which I won't explain in detail. One important difference is
that access parameters allow dispatching (assume R is tagged),
whereas parameter of a named access type do not.
The accessibility rules are different, which is what allows you to say
'Access in some cases with access parameters, where otherwise
'Unchecked_Access would be required.
> Aha! I missed that you couldn't mix "in/out" w/ "access" in a subprogram
> parameter list declaration/definition. Okay, definitely nicer than defining
> 40 access to record types...
You *can* mix 'in out' with 'access':
procedure P(X: in out R; Y: access R);
is legal. Perhaps what you're thinking of is the fact that functions do
not allow 'in out' parameters, so sometimes people use access parameters
instead, when they want a function to have side effects on its
parameters. C functions do that all the time -- e.g., you pass a
"char *", and the function writes upon the thing pointed-to, and *also*
returns some sort of status code.
It seems to me that on the C side, in your Get/Set example, you have
struct parameters passed by copy, and pointer-to-struct parameters. On
the Ada side, the former can correspond to an 'in' mode parameter of a
record type, and the latter can correspond to an access parameter,
or to a parameter of a named access type, or to a parameter of type
System.Address.
I really think the best advice in writing bindings is to look at some
examples. Somebody suggested CLAW, which is a good example. The people
who wrote it have much more experience in this area than I do. If you
don't understand some detail, ask about it here.
- Bob
next prev parent reply other threads:[~2002-11-03 16:47 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-11-01 15:38 Interfacing to C library Eric G. Miller
2002-11-01 17:11 ` Robert A Duff
2002-11-01 17:40 ` tmoran
2002-11-02 5:10 ` Eric G. Miller
2002-11-02 6:02 ` tmoran
2002-11-02 16:10 ` Robert A Duff
2002-11-02 18:35 ` Eric G. Miller
2002-11-02 18:55 ` Robert A Duff
2002-11-02 23:59 ` Eric G. Miller
2002-11-03 16:47 ` Robert A Duff [this message]
2002-11-03 18:55 ` Eric G. Miller
2002-11-03 9:28 ` Dale Stanbrough
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox