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,bbbeae4ed07e9626 X-Google-Attributes: gid103376,public From: "John G. Volan" Subject: Re: Address to function pointer conversion Date: 1997/06/17 Message-ID: <33A74403.4B7C@sprintmail.com>#1/1 X-Deja-AN: 249213287 References: <5nrq5h$13cm@info4.rus.uni-stuttgart.de> <33A1831C.269F@sprintmail.com> Reply-To: johnvolan@sprintmail.com Newsgroups: comp.lang.ada Date: 1997-06-17T00:00:00+00:00 List-Id: Robert Dewar wrote (quoting me): > > John says > ~ > < beyond the scope of the Ada95 standard. In other words, this may be an > implementation-specific (maybe even an OS-specific) thing not defined by > Ada95. There may be no guaranteed portable way to take the address of a > routine (I assume imported from some other language, such as C) and turn > it into an access-to-subprogram. In that case, if you have an > implementation specific solution that works, you may just have to live > with the lack of portability. > >> Later on in this same post which Robert quoted, I suggested: > type Callback_Access_Type is access procedure; > pragma Convention (C, Callback_Access_Type); -- ** is this right? > > function Get_Callback return Callback_Access_Type; > pragma Import (C, Get_Callback, "getCallback"); > > ** What I don't know here is whether this Convention pragma is correct. > But if it is, then this would be a guaranteed portable mechanism for > doing what you want. In his reply, Robert wrote: > If the address is coming from C, then I think the following should be quite > portable: > > type x is access procedure .... > pragma Convention (C, X); > > function Get_Address return x; > pragma Import (C, Get_Address); Excellent! Looks just like what I wrote. > Now your compiler might reject the pragma Convention on X, but it is reasonable > that it shouold be supported, and if it is supported, then it should work. > > Notice this general approach, instead of importing some foreign gizmo from C > like an address, import it in properly typed form, but apply pragma Convention > C to the type. > > This is generally what should be done for access types as well when > communicating with C. Thank you Robert, that answers my question. I didn't know whether this pragma was available for access-to-subprogram types. (I was making an informed guess.) ------------------------------------------------------------------------ Internet.Usenet.Put_Signature (Name => "John G. Volan", Employer => "Texas Instruments Advanced C3I Systems, San Jose, CA", Work_Email => "jvolan@ti.com", Home_Email => "johnvolan@sprintmail.com", Slogan => "Ada95: World's *FIRST* International-Standard OOPL", Disclaimer => "My employer never defined these opinions, so using " & "them would be totally erroneous...or is that just " & "nondeterministic behavior now? :-) "); ------------------------------------------------------------------------