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,4b9c1fb06b190aef X-Google-Attributes: gid103376,public From: bobduff@world.std.com (Robert A Duff) Subject: Re: Q: access to subprogram Date: 1996/07/06 Message-ID: #1/1 X-Deja-AN: 164035198 references: <4rjvo0$7gg@news1.delphi.com> organization: The World Public Access UNIX, Brookline, MA newsgroups: comp.lang.ada Date: 1996-07-06T00:00:00+00:00 List-Id: In article <4rjvo0$7gg@news1.delphi.com>, wrote: >So if one is interfacing with a system that uses call-backs, any target >of a call-back can only appear in the main procedure if the relevant >'type xxx is access procedure yyy' also appears in the main procedure? Clearly, a call-back function has to live "forever" -- you're handing its address off to, say, some windowing system that will call it whenever the mouse is clicked. Therefore, the callback function typically has to live as long as the whole program. Unfortunately, the main subprogram does not last as long as the whole program. Lots of package elaboration can happen before the main subprogram starts, and tasks can keep running for a long time after the main subprogram ends. Given this model, which has existed since Ada 83, it makes no sense to have callbacks nested with the main subprogram (or any other subprogram). You can of course complain that this is the wrong model, or you can complain, yeah but I don't need no stinkin' tasks, so why do I have to be bothered with all this extra complexity. Note also that the main subprogram can be recursive and reentrant. For example, suppose a library package creates a task that calls the main subprogram (in parallel with the "normal" call to the main subprogram, from the environment task). Clearly, there had better not be any callback functions in there. >So even with a wonderful set of bindings done as library routines to >handle all the details, the minimum Windows program requires the user >to write a main procedure (which may be trivial) and a separate package >that does the work. There is no requirement to even have a main procedure at all (in Ada 95). Alternatively, even if there *is* a main subprogram, you should be able to write it in C, if you like. One final point: It's hard for me to get too excited about not being able to put callback functions inside the main subprogram, because lots of people have done lots of callback stuff in C, and you can't put a callback function inside the main function in C, either (you can't nest functions AT ALL in C). - Bob