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.3 required=5.0 tests=BAYES_00,INVALID_DATE, MSGID_SHORT,SUBJ_ALL_CAPS autolearn=no autolearn_force=no version=3.4.4 Path: utzoo!attcan!uunet!tron!beser From: beser@tron.UUCP (Eric Beser) Newsgroups: comp.lang.ada Subject: Re: MOTIF BINDING Summary: handling callbacks Message-ID: <642@tron.UUCP> Date: 17 Sep 90 11:59:10 GMT References: <9009060654.AA09349@ajpo.sei.cmu.edu> Organization: Westinghouse Electronic Systems Group, Baltimore, MD, USA List-Id: In article <9009060654.AA09349@ajpo.sei.cmu.edu>, GBODSO1@NUSVM.BITNET (HC Eng) writes: > a Motif binding. (Please note that I am very new to Ada.) In the OSF Motif > toolkit, widgets are treated as objects and callbacks are passed as subprogram > pointers. I am dying to know how this could be implemented in Ada since Ada > does not have a subprogram type. > Presently I am coding my own "Motif" toolkit in Ada for the IBM RS/6000 and > the stumbling block is the lack of the subprogram type (see Ada LI65). I am > solving the problem very unsatisfactorily by making the interface layer call > a procedure CALLBACK(W) where W is the widget being activated. Inside CALLBACK > is a giant IF and ELSIF block to cater for every widget declared in my program. At the last SigAda meeting in California, the discussion of callbacks in X bindings was interesting, and highly compiler independent. There are other ways to do what you want to do instead of the IF .. ELSIF block. If the compiler supports it, procedure'Address could point to the head of the procedure. However that is not often guaranteed. Task types may be used, and in fact are used in some implementations of XT toolkit. If there is an "Ada way" of doing things, this would fit the bill. There are compiler specific pragmas (i.e. Meridian's pragma call_in_Place) that generate code acceptable to callback, so that procedure'address will actually work the way you want it to. The only other way to pass procedures as arguments are as action procedures in generics. Your generic instantiation can call a C-level interface procedure which calls your callback procedure. What you would do is pass the address of the callback procedure to this interface procedure that uses the C indirect calling mechanism. I am developing a large reusable library for use by the Air Force, and would be curious to see your results. Eric Beser Westinghouse Aerospace Software Engineering (301) - 765 - 1010