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,FREEMAIL_FROM, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,4b27f494a96e0530 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news.glorb.com!wn13feed!worldnet.att.net!bgtnsc04-news.ops.worldnet.att.net.POSTED!53ab2750!not-for-mail Message-ID: <4168EA68.6D6A2B39@yahoo.com> From: CBFalconer Reply-To: cbfalconer@worldnet.att.net Organization: Ched Research X-Mailer: Mozilla 4.75 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: A community Windows binding References: <2004100600261150073%david@bottoncom> <2smd6iF1mo0mcU1@uni-berlin.de> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Sun, 10 Oct 2004 09:04:44 GMT NNTP-Posting-Host: 12.76.142.5 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc04-news.ops.worldnet.att.net 1097399084 12.76.142.5 (Sun, 10 Oct 2004 09:04:44 GMT) NNTP-Posting-Date: Sun, 10 Oct 2004 09:04:44 GMT Xref: g2news1.google.com comp.lang.ada:4982 Date: 2004-10-10T09:04:44+00:00 List-Id: Stephen Leake wrote: > Jeffrey Carter writes: > >> Callbacks and dispatching are essentially the same thing in a >> windowing system. You have to write little pieces of code that >> can be invoked in any order at any time outside your control. >> You have to use global variables extensively for these little >> pieces of code to communicate. The code is difficult to read >> because you have to understand all these little pieces to >> understand any part of the software. > > In Windex, GWindows, CLAW, and GtkAda, each "little piece of > code" has as a parameter the user window type. That type stores > all the information needed; no global variables are necessary. > > I can (with a lot of effort to suppress my normal style :) > write messy, hard to read code in Windex, using global > variables. But it's certainly not required. I disagree that callbacks and dispatching are essentially the same, unless you take the view that the OS and all its processes are one large program, which in turn falls down in the presence of multi-processors. To me, callbacks are simply a way of customizing another piece of software, much as (in C) qsort is customized by a comparison function. Dispatching has to do with selecting a process (or thread) to execute. As an example, there follows an extract from my hashlib.h (complete package available on my site), which has no data space of its own. The hashinit function allocates space in the callers data space, in which it records the location of various customizing functions (all typedef'd in the same header). The package is fully re-entrant, except when calling malloc, etc. All other calls pass back the pointer to that space, much like the 'this' pointer in C++. In many ways hshinit and hshkill are equivalent to fopen and fclose. Not really being familiar with Ada, but lurking here, this is the best I can do for an example of so-called callback functions. This package was, among other things, originally intended to be an example of OO techniques in C, and a testbed for hashing functions. Note that nothing spells out the table size. /* initialize and return a pointer to the data base */ hshtbl *hshinit(hshfn hash, hshfn rehash, hshcmpfn cmp, hshdupfn dupe, hshfreefn undupe, int hdebug); /* 1------------------1 */ /* destroy the data base. Accepts NULL and does nothing */ void hshkill(hshtbl *master); /* 1------------------1 */ /* find an existing entry. NULL == notfound */ void * hshfind(hshtbl *master, void *item); /* 1------------------1 */ /* delete an existing entry. NULL == notfound */ /* Disposal of the storage returned by hshdelete */ /* (originally created by hshdupfn) is up to the */ /* application. It is no longer managed by hashlib */ /* It will usually be disposable by hshfreefn(). */ void * hshdelete(hshtbl *master, void *item); /* 1------------------1 */ /* insert an entry. NULL == failure, else item */ void * hshinsert(hshtbl *master, void *item); -- Chuck F (cbfalconer@yahoo.com) (cbfalconer@worldnet.att.net) Available for consulting/temporary embedded and systems. USE worldnet address!