comp.lang.ada
 help / color / mirror / Atom feed
From: Warren <ve3wwg@gmail.com>
Subject: Re: Callback in Ada (User Data argument)
Date: Mon, 29 Nov 2010 15:24:13 +0000 (UTC)
Date: 2010-11-29T15:24:13+00:00	[thread overview]
Message-ID: <Xns9E3F69D4E88CDWarrensBlatherings@188.40.43.230> (raw)
In-Reply-To: icrshe$lt2$1@tornado.tornevall.net

Jeffrey Carter expounded in
news:icrshe$lt2$1@tornado.tornevall.net: 

> On 11/27/2010 04:32 AM, Georg Bauhaus wrote:
>>
>> 2. Function pointers
>>
>> type To_Be_Applied is access function ( ... );
>> (Or the Ada 2005 anonymous variant if you really need to
>> avoid names.)
> 
> While anonymous access types in current Ada seem designed
> to allow the developer to avoid creating type names and to
> adopt a C-like coding style, in the case of 
> access-to-subprogram, the anonymous form has an advantage
> over named types: they allow passing access to a local
> subprogram ("downward funargs") without any of the
> accessibility checks or worries that accompany named types.

The one area that I've struggled with in callback design is 
the "user data" argument, which is often included in callbacks 
for context (XWindow functions are a good example).  The user 
data argument gives the callback the "context" or "object" for 
which the event is for.

The problem with the "user data" argument, is that you don't 
know what the user's type is going to be (in C, this is given 
as a void *). The Ada dirty approach might be to use 
'System_Address, but that seems wrong. Still another approach 
is to use a generic.

Perhaps the best avenue might be to declare a base tagged 
type, that the user can extend. Then the user data argument 
could be the base classwide type.

Warren



  parent reply	other threads:[~2010-11-29 15:24 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-27  9:47 Callback in Ada Georg Maubach
2010-11-27 10:11 ` Dmitry A. Kazakov
2010-11-27 10:22 ` Ludovic Brenta
2010-11-27 11:04   ` Vinzent Hoefler
2010-11-27 22:05   ` Maciej Sobczak
2010-11-27 10:26 ` Alex Mentis
2010-11-27 10:46 ` Vinzent Hoefler
2010-11-27 11:32 ` Georg Bauhaus
2010-11-27 21:11   ` Jeffrey Carter
2010-11-27 21:20     ` Dmitry A. Kazakov
2010-11-28 21:35       ` Maciej Sobczak
2010-11-29  8:41         ` Dmitry A. Kazakov
2010-11-29 10:12           ` Maciej Sobczak
2010-11-29 11:04             ` Dmitry A. Kazakov
2010-11-30  1:32               ` Randy Brukardt
2010-11-30  8:38                 ` Dmitry A. Kazakov
2010-11-30  9:14                 ` AdaMagica
2010-11-30 12:37                   ` Georg Bauhaus
2010-11-30 20:28                     ` Randy Brukardt
2010-11-30 20:31                   ` Randy Brukardt
2011-01-01 16:46                 ` Yannick Duchêne (Hibou57)
2011-01-02 10:14                   ` AdaMagica
2011-01-02 14:11                     ` Robert A Duff
2011-01-02 15:15                       ` AdaMagica
2011-01-02 15:28                         ` Robert A Duff
2011-01-02 15:38                       ` Alex Mentis
2011-01-02 15:44                         ` Robert A Duff
2011-01-03 21:38                           ` Randy Brukardt
2011-01-04  0:11                             ` Robert A Duff
2011-01-04 18:33                             ` Alex Mentis
2011-01-04 19:47                               ` Robert A Duff
2011-01-04 20:21                                 ` Randy Brukardt
2011-01-04 20:15                               ` Randy Brukardt
2010-11-29 15:24     ` Warren [this message]
2010-11-30  1:35       ` Callback in Ada (User Data argument) Randy Brukardt
2010-11-30 16:51         ` Warren
replies disabled

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