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=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,72a0bc6240d264e3 X-Google-Attributes: gid103376,public From: Jeff Carter Subject: Re: Access and alias Date: 2000/04/07 Message-ID: <38ED2460.479B044C@acm.org>#1/1 X-Deja-AN: 607796887 Content-Transfer-Encoding: 7bit References: <86d7o5ae23.fsf@ppp-169-201.villette.club-internet.fr> <86aej9aa8y.fsf@ppp-169-201.villette.club-internet.fr> <38EB55AE.D4A241FD@icn.siemens.de> <8cfnpd$3h7$1@nnrp1.deja.com> <38EBBBBE.87C93900@acm.org> <38EC8032.1284C1F0@icn.siemens.de> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.prod.itd.earthlink.net 955069075 63.10.53.178 (Thu, 06 Apr 2000 17:57:55 PDT) Organization: EarthLink Inc. -- http://www.EarthLink.net MIME-Version: 1.0 Reply-To: jrcarter@acm.org NNTP-Posting-Date: Thu, 06 Apr 2000 17:57:55 PDT Newsgroups: comp.lang.ada Date: 2000-04-07T00:00:00+00:00 List-Id: Alfred Hilscher wrote: > > Jeff Carter wrote: > > If you have to pass null, access types (with convention C) work fine. If > > you don't have to pass null, in out works for procedures, and access > > parameters work for functions. All keep the type checking that addresses > > lose: > > > > -- int func (int* I); > > > > function F1 (I : System.Address) return Int; > > pragma Import (C, F1, "func"); > > > > function F2 (I : access Int) return Int; > > pragma Import (C, F2, "func"); > > > > I : aliased Int; > > J : Int; > > S : String := Get; I see I forgot to put "aliased" on the declaration of S. Sorry. > > > > ... > > > > J := F1 (I'Address); -- works as intended > > J := F1 (S'Address); -- works as not intended > > J := F2 (I'access); -- works as intended > > J := F2 (S'access); -- compilation error > > OK. But I would do a little change: > > Instead of: > function F2 (I : access Int) return Int; > pragma Import (C, F2, "func"); > > Would write > type Int_Access is access all INT; > function F2 (I : Int_Access) return Int; > pragma Import (C, F2, "func"); > > This avoids some problems that I had with anonymous access types. Yes, if you have to pass null, this is the way to do it. BE sure to put a pragma Convention (C, Int_Access) in there. Then you declare P : Int_Access; ... J := F2 (P); and presumably the C function knows what to do with the null. -- Jeff Carter "We burst our pimples at you." Monty Python & the Holy Grail