| Author |
Message |
Boris Mohar
Guest
|
Posted:
Tue Dec 21, 2004 1:39 am Post subject:
Re: what's a callback? |
|
|
On Mon, 20 Dec 2004 18:46:48 +0000, John Woodgate
<jmw@jmwa.demon.contraspam.yuk> wrote:
| Quote: | I read in sci.electronics.design that Boris Mohar <borism_-void-
_@sympatico.ca> wrote (in <u62es05or1funpn48pp79m00s1b4n6uq4e@4ax.com>)
about 'what's a callback?', on Mon, 20 Dec 2004:
Looks like a giant maggot.. Fancy some geoduck?
I can't even pronounce it.
|
http://www.olywa.net/cook/faq.htm
Regards,
Boris Mohar
Got Knock? - see:
Viatrack Printed Circuit Designs http://www3.sympatico.ca/borism/ |
|
| Back to top |
|
 |
Rich Grise
Guest
|
Posted:
Tue Dec 21, 2004 7:58 am Post subject:
Re: what's a callback? |
|
|
On Mon, 20 Dec 2004 12:16:38 -0500, Boris Mohar wrote:
I thought it was goeduck. Isn't that feeding tube just meat, though? I
could see eating snail foot - I've never tried an oyster because it'd be
too much like eating little piles of guts.
I wish I could find some dried abalone - I should shop around the Asian
neighborhoods. In Korea, they had sun-dried squid, which was really quite
tasty. In Thailand, they have sun-dried lizard on a stick. Never tried one
of those. :-)
Cheers!
Rich |
|
| Back to top |
|
 |
Rich Grise
Guest
|
Posted:
Tue Dec 21, 2004 7:58 am Post subject:
Re: what's a callback? |
|
|
On Tue, 21 Dec 2004 04:14:31 +0000, Rich Grise wrote:
And I was wrong. :-)
According to my local dictionary, it's just geo-duck, like geocities.
Unless it's supposed to be a hard "g", as in "gooey".
Thanks!
Rich |
|
| Back to top |
|
 |
Rene Tschaggelar
Guest
|
Posted:
Tue Dec 21, 2004 4:28 pm Post subject:
Re: what's a callback? |
|
|
John Larkin wrote:
| Quote: | A few programmers I've known have used the term "callback", which
somehow related to executing a deferred subroutine or something. Does
anybody know anything about this term or its conventions? If I google
it, I just get a lot of telephone-type references.
|
A callback is a function call to a fuction that at design
time does not yet exist.
Rene
--
Ing.Buero R.Tschaggelar - http://www.ibrtses.com
& commercial newsgroups - http://www.talkto.net |
|
| Back to top |
|
 |
Steve at fivetrees
Guest
|
Posted:
Tue Dec 21, 2004 5:04 pm Post subject:
Re: what's a callback? |
|
|
"Rene Tschaggelar" <none@none.net> wrote in message
news:41c808c4$0$30029$5402220f@news.sunrise.ch...
| Quote: |
A callback is a function call to a fuction that at design
time does not yet exist.
|
What a strange thread. Full of misinformation such as this.
Steve
http://www.fivetrees.com |
|
| Back to top |
|
 |
Rene Tschaggelar
Guest
|
Posted:
Tue Dec 21, 2004 5:49 pm Post subject:
Re: what's a callback? |
|
|
Steve at fivetrees wrote:
| Quote: | "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.
What a strange thread. Full of misinformation such as this.
|
Ah yes? All callbacks I worked with involved function whichs
specs were defined roughly but not implemented yet.
The proceedings involved writing this function and supplying
a pointer to it to the already existing code.
No?
Rene |
|
| Back to top |
|
 |
Frank Bemelman
Guest
|
Posted:
Tue Dec 21, 2004 5:57 pm Post subject:
Re: what's a callback? |
|
|
"Steve at fivetrees" <steve@NOSPAMTAfivetrees.com> schreef in bericht
news:5cSdnbzGW5zYjFXcRVn-jg@nildram.net...
| Quote: | "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.
What a strange thread. Full of misinformation such as this.
|
90% of the responses were pretty much okay. That is not 'Full
of misinformation'.
Of course you don't bother to give any meaningful response
yourself. Like the majority of CAE, bunch of arrogant, boring
wannabees as they are.
--
Thanks, Frank.
(remove 'q' and 'invalid' when replying by email) |
|
| Back to top |
|
 |
Frank Bemelman
Guest
|
Posted:
Tue Dec 21, 2004 6:04 pm Post subject:
Re: what's a callback? |
|
|
"Rene Tschaggelar" <none@none.net> schreef in bericht
news:41c81bc6$0$30025$5402220f@news.sunrise.ch...
| Quote: | Steve at fivetrees 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.
What a strange thread. Full of misinformation such as this.
Ah yes? All callbacks I worked with involved function whichs
specs were defined roughly but not implemented yet.
The proceedings involved writing this function and supplying
a pointer to it to the already existing code.
No?
|
I'd say yes, now that you described it a bit better.
--
Thanks, Frank.
(remove 'q' and 'invalid' when replying by email) |
|
| Back to top |
|
 |
Active8
Guest
|
Posted:
Tue Dec 21, 2004 6:53 pm Post subject:
Re: what's a callback? |
|
|
On Tue, 21 Dec 2004 14:04:56 +0100, "Frank Bemelman"
<f.bemelmanq@xs4all.invalid.nl> wrote:
| Quote: | "Rene Tschaggelar" <none@none.net> schreef in bericht
news:41c81bc6$0$30025$5402220f@news.sunrise.ch...
Steve at fivetrees 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. 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.
I think there's a terminology problem, here.
Prototype:
Function(int num, double, mag);
Definition - this is implementation:
Function(int num, double, mag)
{
// some crap code - or none at all
return num; //default return is int :)
}
| Quote: |
What a strange thread. Full of misinformation such as this.
Ah yes? All callbacks I worked with involved function whichs
specs were defined roughly but not implemented yet.
The proceedings involved writing this function and supplying
a pointer to it to the already existing code.
No?
I'd say yes, now that you described it a bit better.
|
Even an empty function is an *implementation* of a function.
I can write:
call bogus_pointer
for PIC and as long as there's a label "bogus_pointer", it'll go
there. That's an implementation. But that doesn't mean it won't
execute right on past the return that I forgot to include and f*ck
everything up.
So I include the return stmnt and everything's fine.
But to get back OT :) a good example of a call back is the function
pointer that must be passed to the "CreateWindow()" function in
winders API. It's the "WndProc" function in the prototype.
When winders OS needs to send a message (you clicked the little "x" in
the text editor) to a window it calls that WndProc function with a
handle to that window.
The callback can be static, i.e., it is shared by all processes
calling it.
The neat thing is that in the WndProc function, you can create a
controller object that stores (via SetWidowsLong(hWnd, ...) you pass
the window handle to identify which window) a pointer to itself in the
window's reserved data space.
Now the callback can access the controller object for that particular
window (say you have 2 text edit windows open in the same app) and
check whether you saved that text file yet. Or whatever.
But f*ck all that noise. Just use wxWidgets ! :) That's open source
and cross platform and used by major corps.
--
Best Regards,
Mike |
|
| Back to top |
|
 |
Steve at fivetrees
Guest
|
Posted:
Tue Dec 21, 2004 7:17 pm Post subject:
Re: what's a callback? |
|
|
"Frank Bemelman" <f.bemelmanq@xs4all.invalid.nl> wrote in message
news:41c81d6d$0$432$e4fe514c@news.xs4all.nl...
| Quote: | What a strange thread. Full of misinformation such as this.
90% of the responses were pretty much okay. That is not 'Full
of misinformation'.
|
Granted. However the 10% were fairly forceful ;).
| Quote: | Of course you don't bother to give any meaningful response
yourself. Like the majority of CAE, bunch of arrogant, boring
wannabees as they are.
|
CAE? not sure I know this one (other than Computer Aided Engineering).
Ok - meaningful response then. Rene said:
| Quote: | A callback is a function call to a fuction that at design time does not
yet exist. |
That's one potential/peripheral/trivial use, sure (esp. once he'd provided
more detail), but it's not what defines a callback. More generally, a
callback is a means of providing an instance-specific hook into a
general-purpose process (a form of polymorphism, if you like). The simplest
example I can think of is a state machine, where each state corresponds to a
specific processing routine. You can deal with this via a case structure,
sure, but it's neater (and more robust) to use an array of function
pointers.
A more real-world example would be a class that exists to process input from
e.g. a file. Let's say that each "item" in the file is processed by a
general-purpose handler class, but is finally validated and stored by a
routine that is specific to the nature of the item encountered. Within the
uberclass definition one could include a function pointer (the callback);
within the instance of the class one would point this at the specific
routine.
Another example is a registered callback (described by others here), where a
function pointer is passed to a class at runtime (e.g. qsort). I use static
callbacks all the time, but registered callbacks much less so.
Hope this redresses the balance ;).
Steve
http://www.fivetrees.com |
|
| Back to top |
|
 |
Hans-Bernhard Broeker
Guest
|
Posted:
Tue Dec 21, 2004 7:43 pm Post subject:
Re: what's a callback? |
|
|
In comp.arch.embedded Active8 <replyt2group@ndbbm.net> wrote:
| Quote: | "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.
| Quote: | 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.
| Quote: | 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. |
|
| Back to top |
|
 |
Active8
Guest
|
Posted:
Tue Dec 21, 2004 9:30 pm Post subject:
Re: what's a callback? |
|
|
On 21 Dec 2004 14:43:13 GMT, Hans-Bernhard Broeker
<broeker@physik.rwth-aachen.de> wrote:
| Quote: | 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.
|
Something has to be declared or it won't compile. I know, that's not
a definition, just a generic function pointer. As you go on, it
becomes more clear what you're trying to say (I practiced this same
excersize with Kevin :) ) so don't feel compelled to comment on all
my comments.
| Quote: | More importantly, different calls to
'foo' may want to use different functions 'bar', at least some of
which aren't written yet.
|
That's called function overloading and another way is polymorphism.
You can't *link* a function call to a function with no definition,
If it's *declared" in a header or somewhere "in scope", it will
*compile* but if the definition hasn't been written, the linker
won't find it's entry point in any modules and it won't *link*. But
that's not a generic function pointer I'm talking about.
IOW, you can't assign a *valid* pointer at runtime unless the
function is defined somewhere.
pfunc = atan;
won't work if the linker can't find atan.
pfunc = NULL;
pfunc = atan;
function(pfunc);
groovy, now hit "execute".
| Quote: |
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'.
|
As I said, I can pass any bogus pointer in a function. The fact is,
that function must have been defined (implemented) somewhere or it
won't link. At design time, not run time. You can grab a valid
pointer at runtime, but there *will be no valid pointer unless the
function was implemented and compiled in a module that the linker
can see.*
Period.
| Quote: |
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.
|
None of this changes the fact that it won't link. Won't even compile
without a declaration.
function(void){}
void (*pfunc) ();
function(pfunc);
This will compile and link, but if you run this code, you have to
assign a value (address) to the function pointer pfunc and you
can't get that address if it's stilll vaporware.
None of this changes the fact that this ain't the definition of a
callback function.
This is funny. I just typed __define callback function__ into
google and didn't get any returns about phones.
http://gethelp.devx.com/techtips/cpp_pro/10min/10min0300.asp
<quote>
A callback function is one that is not invoked explicitly by the
programmer; rather the responsibility for its invocation is
delegated to another function that receives the callback function's
address.
</quote>
Period.
| Quote: |
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.
|
where's the linker gonna get the damn valid pointer from, it's ass?
| Quote: | 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.
|
Good. Now click "Execute". Oh. You're waiting on another group to
implement your function? So you wrote what's known to me as a
"stub". You could just as easily write an empty function if you
don't need the flexibility of function pointers.
say
func(){}
function(func);
and the function "function" will get the pointer to func and execute
it as a "callback". It's still a callback regardless of whether it's
implemented.
-
Best Regards,
Mike |
|
| Back to top |
|
 |
Active8
Guest
|
Posted:
Tue Dec 21, 2004 9:48 pm Post subject:
Re: what's a callback? |
|
|
On Sun, 19 Dec 2004 15:43:11 -0500, Spehro Pefhany wrote:
| Quote: | On Sun, 19 Dec 2004 12:09:55 -0800, the renowned John Larkin
john@spamless.usa> wrote:
A few programmers I've known have used the term "callback", which
somehow related to executing a deferred subroutine or something. Does
anybody know anything about this term or its conventions? If I google
it, I just get a lot of telephone-type references.
I'm doing a thing now where, in an interrupt service routine, if I
think I'm out of time I set a flag to remind me to finish some chores
next time or so. I'm not sure if that qualifies as a "callback."
John
AFAIUI, a callback handler is essentially like asychronous logic- it's
a routine (that you register with some other piece of software) that
gets called when some specific set of conditions arise.
|
Like when the code executes it. You're talking about an event with a
callback. Normally you wait on that in a thread callback function.
Example: My sound recorder/scope. The soundcard API funcs set an
"Event" when there's data ready. I passed the address of a callback
to whatever it was. The callback function (I wrote) sets an event
and my processing thread (also has a callback) deals with the data
when it returns from WaitForSingleOblect(my_event_handle) . I think
I used an unneccessary indirection there, but wtf?
It would have been better to get a handle to that event and just
wait on it in a thread callback.
pass the thread callback func pointer to the API func.
then in my thread callback:
WaitForSingleObject(HANDLE event_handle);
But you need the event handle. So I set my own event in a separate
callback. Oh! I can't pass the thread callback to the api because it
gets called when the thread is created and the thread terminates
when the callback function returns.
| Quote: |
The business of sharing resources between threads in a threaded
environment (where you can, for some purposes, pretend that the
computer is executing multiple bits of software simultaneously) is
fairly complex and involves a lot of fairly odd terminology (mutex,
semaphore etc.) Most of my stuff doesn't have an RTOS so neither the
facilities or the complexity are there.
|
Thanks for the refresher.
--
Best Regards,
Mike |
|
| Back to top |
|
 |
Active8
Guest
|
Posted:
Tue Dec 21, 2004 9:51 pm Post subject:
Re: what's a callback? |
|
|
On Sun, 19 Dec 2004 21:50:21 GMT, Anthony Fremont wrote:
| Quote: | "Fred Bloggs" <nospam@nospam.com> wrote in message
No- that is called "setting a flag to remind you to finish some
chores"
and is an example of *re-entrant code*:-) Why in the world would that
be
called "callback" unless you collect useless jargon?
That's certainly the most unique definition of re-entrancy that I've
seen.
When I think of re-entrant code, I think of code that has no local
variable storage associated to it. I also think of code that can call
itself recursively or be executed in several threads across multiple
processors concurrently with only one copy in memory.
|
That's called static linking.
--
Best Regards,
Mike |
|
| Back to top |
|
 |
Active8
Guest
|
Posted:
Tue Dec 21, 2004 10:01 pm Post subject:
Re: what's a callback? |
|
|
On Sun, 19 Dec 2004 14:04:30 -0800, John Larkin wrote:
| Quote: | On Sun, 19 Dec 2004 21:50:21 GMT, "Anthony Fremont"
spam@anywhere.com> wrote:
"Fred Bloggs" <nospam@nospam.com> wrote in message
No- that is called "setting a flag to remind you to finish some
chores"
and is an example of *re-entrant code*:-) Why in the world would that
be
called "callback" unless you collect useless jargon?
That's certainly the most unique definition of re-entrancy that I've
seen.
When I think of re-entrant code, I think of code that has no local
variable storage associated to it. I also think of code that can call
itself recursively or be executed in several threads across multiple
processors concurrently with only one copy in memory.
AKA "pure" code.
Reentrant code means that a program can have more than one thread |
executing concurrently.
http://vergil.chemistry.gatech.edu/resources/programming/threads.html
--
Best Regards,
Mike |
|
| Back to top |
|
 |
|
|
|
|