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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,de7dd126d6737f3a X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!feeder.news-service.com!85.214.198.2.MISMATCH!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Warren Newsgroups: comp.lang.ada Subject: Re: Callback in Ada (User Data argument) Date: Mon, 29 Nov 2010 15:24:13 +0000 (UTC) Organization: A noiseless patient Spider Message-ID: References: <8lc2d0Fb6jU1@mid.individual.net> <4cf0ec67$0$6882$9b4e6d93@newsspool2.arcor-online.net> Injection-Date: Mon, 29 Nov 2010 15:24:13 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="9f8M0iN5t54V+4DF/iqO8g"; logging-data="29173"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18bWTeo8OqdpZnzK/LwKGlq6ckU7u4Tp7U=" User-Agent: Xnews/5.04.25 X-Face: &6@]C2>ZS=NM|HE-^zWuryN#Z/2_.s9E|G&~DRi|sav9{E}XQJb*\_>=a5"q]\%A;5}LKP][1mA{gZ,Q!j Cancel-Lock: sha1:lCwCsLsA3MI+I8MxFIx9ysIpiCg= Xref: g2news1.google.com comp.lang.ada:15699 Date: 2010-11-29T15:24:13+00:00 List-Id: 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