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: 163632547 references: <4rd5lu$q4@mulga.cs.mu.OZ.AU> <4re8bj$qfk@krusty.irvine.com> organization: The World Public Access UNIX, Brookline, MA newsgroups: comp.lang.ada Date: 1996-07-03T00:00:00+00:00 List-Id: In article <4re8bj$qfk@krusty.irvine.com>, Adam Beneschan wrote: >It should be noted that the new object-oriented features of Ada 95 >should make subprogram accesses less necessary than before. Abstract >types inherently possess subprogram pointers, so it should be possible >to take advantage of this feature as an alternative to explicit >subprogram accesses. Quite right. The only problem is that it's a bit verbose. > procedure P1 is > > type My_Error_Handler is new Error_Handler with record > Error_File : Text_IO.File_Type; > end record; You need to put: procedure Handle_Error (Handler : in My_Error_Handler; Message : in string); here, to avoid freezing rules rearing their ugly head. > EH : My_Error_Handler; > -- variable name chosen to avoid being fired :) > > procedure Handle_Error (Handler : in My_Error_Handler; > Message : in string) is > begin > Text_IO.Put_Line (Handler.Error_File, Message); > end Handle_Error; > > begin > Text_IO.Create (EH.Error_File, ... > ... > Pack1.Do_Some_Big_Procedure_That_Can_Report_Errors (EH); > >This mechanism doesn't let you *directly* store an access to a >subprogram in a global variable, the way subprogram accesses do; but >using accesses to Error_Handler objects should let you accomplish the >same thing. Right. Quite often, if you think you want a pointer to a procedure, a class-wide object is better. >Once again, my apologies if my Ada 95 syntax is incorrect. I haven't >yet learned all the nuances of Ada 95 programming. Mainly, I wanted >to discuss the concepts involved; someone else may need to fill in the >programming details. You've got the concepts quite right. No need to apologize for violating a freezing rule. ;-) My only objection to this technique is that it's a lot of verbiage for a pretty trivial thing. - Bob