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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,86ec22e070e319c0 X-Google-Attributes: gid103376,public From: Stephen Leake Subject: Re: How do I get this to work?? Date: 1999/01/07 Message-ID: #1/1 X-Deja-AN: 429920101 References: <76s0dp$1v4$1@nntp3.uunet.ca> <76tbvv$ba5$1@nntp3.uunet.ca> <770ifd$qui$1@goblin.uunet.ca> Organization: NASA Goddard Space Flight Center -- Greenbelt, Maryland USA Newsgroups: comp.lang.ada Date: 1999-01-07T00:00:00+00:00 List-Id: "Chris Warwick" writes: > Stephen Leake wrote in message ... > > >Why does Close_Port need a pointer to a Session? If you are passing > >Session to C code, you should probably use 'Address rather than > >'access. Or, define Close_Port to take an access parameter: As Robert Dewar pointed out, this was bad advice. Aparently too much xmas turkey clogged the arteries to my brain :) The current advice (I believe) is to declare the Ada procedure to take an 'in' or 'in out' parameter, and let the compiler pass this to the C code by reference. This only works if the C code doesn't allow a null pointer as a valid option; the correct way to pass a parameter that can either be a null pointer or a pointer to an object is with an access type parameter, and 'Unchecked_Access. > I am indeed passing this to some C code, and I realize that what I am doing > is cheating, just a little. The reason is I can't seem to get the stuff to > the C function by value, if I pass it by reference its happy, but it barfs > when I try to do it by value. Post the code that fails to "pass by value"; maybe we can tell you what's wrong with it. > My old trick of translating pointers into Ada types by creating a function > to return the record by value also doesn't work... > > >function Close_Port (Session : access Session_Type); > > > >If you really, really need the interface you've given, > >'unchecked_access will eliminate the error message. > > > Thanks, it does indeed eliminate the error, but it leaves me with a bad > taste. Somewhat like resorting to an unchecked_conversion. I agree with the other comments here; the bad taste is from not knowing what will happen to the pointer when you pass it to C. That's why it is "unchecked". > Is there a "proper" way to do this, or am I stuck with the unchecked > solution? If you don't need to be able to pass a null pointer, passing as an 'in' or 'in out' parameter should work, and would be the proper solution. -- Stephe