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,99ab4bb580fc34cd X-Google-Attributes: gid103376,public From: bobduff@world.std.com (Robert A Duff) Subject: Re: Q: access to subprogram Date: 1996/07/03 Message-ID: #1/1 X-Deja-AN: 163465891 references: <4rb9dp$qe6@news1.delphi.com> <4rd5lu$q4@mulga.cs.mu.OZ.AU> organization: The World Public Access UNIX, Brookline, MA newsgroups: comp.lang.ada Date: 1996-07-03T00:00:00+00:00 List-Id: In article <4rd5lu$q4@mulga.cs.mu.OZ.AU>, Fergus Henderson wrote: >What was the safe way that you proposed? There were two variations, actually. 1. Limited access types. You would say: type T is limited access procedure(...); T would be limited, meaning no assignment. Without assignment, you can't create dangling pointers to procedures. You could pass values of type T into subprograms, but all the subprogram could do is call through that value, or pass it on -- not copy it into a global variable. 2. Access-to-subprogram parameters. You would say: procedure Foo(X: Integer; Y: access procedure(B: Boolean)); This syntax is reminiscent of Pascal's. There would be a run-time accessibility check on various operations on Y, just like the access parameters that DO exist in the language (e.g. "Y: access Integer"). This would allow you to pass procedures around, and call them, as in option (1). You could also copy them to *local* variables (that is, inside Foo, you could say "Local := Local_Access_Type(Y)), but any attempt to copy to a global variable would require some sort of type_conversion or whatever that would fail the run-time check. I preferred option (1) at the time. Now, GNAT has gone and provided the same capability, using an implementation-defined attribute (Unrestricted_Access), but unfortunately, this attribute allows dangling pointers to subprograms, unlike either of the above options. - Bob