Re: what's a callback?
From: Hans-Bernhard Broeker (broeker_at_physik.rwth-aachen.de)
Date: 12/21/04
- Next message: Nicholas O. Lindan: "Re: Is zero even or odd?"
- Previous message: daestrom: "Re: Removing impedance protection from MOEPED #3"
- In reply to: Active8: "Re: what's a callback?"
- Next in thread: Active8: "Re: what's a callback?"
- Reply: Active8: "Re: what's a callback?"
- Messages sorted by: [ date ] [ thread ]
Date: 21 Dec 2004 14:43:13 GMT
In comp.arch.embedded Active8 <replyt2group@ndbbm.net> wrote:
> >> > "Rene Tschaggelar" <none@none.net> wrote in message
> >> > news:41c808c4$0$30029$5402220f@news.sunrise.ch...
> >> >>A callback is a function call to a fuction that at design
> >> >>time does not yet exist.
> Not even remotely true, let alone possible to compile.
It's actually a lot more true than you believe. Rene may have
condensed its essence down to a little too few words for you to
recognize it, but he did get it right.
> The function *must* exist, however you can select a function and
> pass a pointer at runtime.
> You can't even compile a function in C++ without an implementation.
Correct, but that's not the issue at hand. We're talking about the
not-yet-existing implementation of a _called_ function, not its
caller.
To rephrase Rene's statement: a callback is what you use if a function
'foo' needs to be written now, which has to call another function
'bar' that may not exist yet. More importantly, different calls to
'foo' may want to use different functions 'bar', at least some of
which aren't written yet.
So you declare the interface signature of 'bar', and make a pointer to
a function of that signature (or, in OO, an object implementing that
interface) part of the set of arguments passed to 'foo'.
The central aspect that makes this a good idea (compared to other
methods of selecting a function to call from a collection, e.g. an
index into a table of function pointers, or a switch() between a lot
of function calls), is indeed, as Rene pointed out, that it lets you
split up "compile time" into at least two separate phases, to be
carried out by different people, at different places and times: one is
the compilation time of 'foo', the other the (potentially lots of)
compilations of 'bar', and also of the function that calls 'foo' and
passes 'bar' to it.
> Even an empty function is an *implementation* of a function.
But an empty function is not part of this design --- there's just the
prototype, and a *pointer* to such a function. But no actual
implementation of any such function is involved in this design pattern
named "callback". That's how you can implement the pattern, without
having any implementation of the actual callback function at hand.
-- Hans-Bernhard Broeker (broeker@physik.rwth-aachen.de) Even if all the snow were burnt, ashes would remain.
- Next message: Nicholas O. Lindan: "Re: Is zero even or odd?"
- Previous message: daestrom: "Re: Removing impedance protection from MOEPED #3"
- In reply to: Active8: "Re: what's a callback?"
- Next in thread: Active8: "Re: what's a callback?"
- Reply: Active8: "Re: what's a callback?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|