comp.lang.ada
 help / color / mirror / Atom feed
From: CBFalconer <cbfalconer@yahoo.com>
Subject: Re: A community Windows binding
Date: Sun, 10 Oct 2004 09:04:44 GMT
Date: 2004-10-10T09:04:44+00:00	[thread overview]
Message-ID: <4168EA68.6D6A2B39@yahoo.com> (raw)
In-Reply-To: mailman.249.1097328040.390.comp.lang.ada@ada-france.org

Stephen Leake wrote:
> Jeffrey Carter <spam@spam.com> 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.
   <http://cbfalconer.home.att.net>  USE worldnet address!





  reply	other threads:[~2004-10-10  9:04 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <usm8shkul.fsf@acm.org>
2004-10-05 23:28 ` A community Windows binding Stephen Leake
2004-10-06  4:26   ` David Botton
2004-10-06 17:42     ` Jeffrey Carter
2004-10-07 16:33       ` Warren W. Gay VE3WWG
2004-10-07 17:37         ` Jeffrey Carter
2004-10-08  2:39           ` Alexander E. Kopilovich
2004-10-08  2:43           ` Nick Roberts
2004-10-08  4:56             ` tmoran
2004-10-08 23:17             ` chris
2004-10-09  1:31             ` Jeffrey Carter
2004-10-09  1:36             ` Jeffrey Carter
2004-10-09  3:15               ` Steve
2004-10-09  6:23                 ` tmoran
     [not found]                 ` <z7ybd.26154$hk6.998363@news20.bellglobal.com>
2004-10-15  1:12                   ` Stephen Leake
2004-10-15 20:36                     ` David Botton
2004-10-17 13:25                       ` Stephane Riviere
2004-10-09 13:20               ` Stephen Leake
2004-10-10  9:04                 ` CBFalconer [this message]
2004-10-10 14:39                   ` Stephen Leake
2004-10-14 16:54                     ` Warren W. Gay VE3WWG
2004-10-14 16:53                   ` Warren W. Gay VE3WWG
2004-10-10  3:38               ` David Botton
2004-10-14 16:46             ` Warren W. Gay VE3WWG
     [not found]           ` <rSftVP19_F@VB1162.spb.edu>
2004-10-08  8:18             ` Marius Amado Alves
2004-10-08  1:36         ` Stephen Leake
2004-10-06  4:28   ` CBFalconer
2004-10-06  6:02     ` tmoran
2004-10-06 11:35     ` Georg Bauhaus
2004-10-06 14:04       ` Steve
2004-10-06  6:22   ` Fionn mac Cuimhaill
2004-10-06 17:18   ` Nick Roberts
2004-10-07  6:38   ` Frank Piron
2004-10-07  9:44   ` Ross Higson
2004-10-07 16:39     ` Warren W. Gay VE3WWG
2004-10-07 22:27       ` Ross Higson
     [not found] <41664D4E.7040405@netcabo.pt>
2004-10-08 21:38 ` Alexander E. Kopilovich
     [not found] <uacv0hhj0.fsf_-_@acm.org>
2004-10-10 18:05 ` Stephen Leake
2004-10-10 18:17   ` Andre
2004-10-10 20:55     ` tmoran
2004-10-11  0:34   ` David Botton
2004-10-11  0:39   ` David Botton
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox