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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,64a6ad02ec510120 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-11-03 08:48:15 PST Newsgroups: comp.lang.ada Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!arclight.uoregon.edu!news.tufts.edu!uunet!dca.uu.net!ash.uu.net!world!news From: Robert A Duff Subject: Re: Interfacing to C library... User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Sender: news@world.std.com (Mr Usenet Himself) Message-ID: Date: Sun, 3 Nov 2002 16:47:47 GMT Content-Type: text/plain; charset=us-ascii References: NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Organization: The World Public Access UNIX, Brookline, MA Xref: archiver1.google.com comp.lang.ada:30320 Date: 2002-11-03T16:47:47+00:00 List-Id: "Eric G. Miller" 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