Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #27685 > unrolled thread
| Started by | gnuist007@hotmail.com |
|---|---|
| First post | 2012-10-25 12:24 -0700 |
| Last post | 2012-10-26 14:08 -0400 |
| Articles | 20 on this page of 23 — 13 participants |
Back to article view | Back to comp.lang.c
avcall, callback, trampoline, vacall, etc gnuist007@hotmail.com - 2012-10-25 12:24 -0700
Re: avcall, callback, trampoline, vacall, etc James Kuyper <jameskuyper@verizon.net> - 2012-10-25 16:04 -0400
Re: avcall, callback, trampoline, vacall, etc fmassei@gmail.com - 2012-10-25 13:08 -0700
Re: avcall, callback, trampoline, vacall, etc James Kuyper <jameskuyper@verizon.net> - 2012-10-25 16:12 -0400
Re: avcall, callback, trampoline, vacall, etc fmassei@gmail.com - 2012-10-25 13:23 -0700
Re: avcall, callback, trampoline, vacall, etc Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2012-10-25 20:01 -0600
Re: avcall, callback, trampoline, vacall, etc Gene Wirchenko <genew@ocis.net> - 2012-10-25 14:55 -0700
Re: avcall, callback, trampoline, vacall, etc Paavo Helde <myfirstname@osa.pri.ee> - 2012-10-25 15:46 -0500
Re: avcall, callback, trampoline, vacall, etc "James K. Lowden" <jklowden@speakeasy.net> - 2012-10-25 18:53 -0400
Re: avcall, callback, trampoline, vacall, etc Öö Tiib <ootiib@hot.ee> - 2012-10-26 13:18 -0700
Re: avcall, callback, trampoline, vacall, etc fmassei@gmail.com - 2012-10-26 13:33 -0700
Re: avcall, callback, trampoline, vacall, etc Cortez <relativeflux@hotmail.co.uk> - 2012-10-25 13:47 -0700
Re: avcall, callback, trampoline, vacall, etc Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2012-10-25 20:18 -0600
Re: avcall, callback, trampoline, vacall, etc gnuist007@hotmail.com - 2012-10-26 10:11 -0700
Re: avcall, callback, trampoline, vacall, etc Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-10-27 18:17 +0000
Re: avcall, callback, trampoline, vacall, etc Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2012-10-27 21:35 -0600
Re: avcall, callback, trampoline, vacall, etc Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-10-29 12:38 +0000
Re: avcall, callback, trampoline, vacall, etc "Pascal J. Bourguignon" <pjb@informatimago.com> - 2012-10-28 18:56 +0100
Re: avcall, callback, trampoline, vacall, etc Rivka Miller <rivkaumiller@gmail.com> - 2012-11-05 16:28 -0800
Re: avcall, callback, trampoline, vacall, etc Les Cargill <lcargill99@comcast.com> - 2012-10-26 07:27 -0500
Re: avcall, callback, trampoline, vacall, etc gnuist007@hotmail.com - 2012-10-26 10:16 -0700
Re: avcall, callback, trampoline, vacall, etc Les Cargill <lcargill99@comcast.com> - 2012-10-26 12:42 -0500
Re: avcall, callback, trampoline, vacall, etc James Kuyper <jameskuyper@verizon.net> - 2012-10-26 14:08 -0400
Page 1 of 2 [1] 2 Next page →
| From | gnuist007@hotmail.com |
|---|---|
| Date | 2012-10-25 12:24 -0700 |
| Subject | avcall, callback, trampoline, vacall, etc |
| Message-ID | <dfa26195-ed53-41e7-afb6-6f59d556a154@3g2000yqn.googlegroups.com> |
Dear Programming Gurus, These concepts are rather well talked about .. over the internet and usenet, however, I cant find any clear explanation. avcall, callback, trampoline, vacall, etc I looked in a book of C programming, ie k&r and also the rationale for C, an old copy and could not find any explanation. I know that javascript books talk a lot about callbacks and there is the style of programming involving writing callbacks and registering them. Unfortunately, in the age when I took my C class, there was no discussion along these lines. Can anyone give clear definition, example, benefits, variations, origin or citation to a paper where it originated and explained first, as well as some modern text that does the better than most job of illustrating it and its applications.
[toc] | [next] | [standalone]
| From | James Kuyper <jameskuyper@verizon.net> |
|---|---|
| Date | 2012-10-25 16:04 -0400 |
| Message-ID | <50899B3A.6090403@verizon.net> |
| In reply to | #27685 |
On 10/25/2012 03:24 PM, gnuist007@hotmail.com wrote: > Dear Programming Gurus, > > These concepts are rather well talked about .. over the internet and > usenet, however, I cant find any clear explanation. > > avcall, callback, trampoline, vacall, etc > > I looked in a book of C programming, ie k&r and also the rationale for > C, an old copy and could not find any explanation. > > I know that javascript books talk a lot about callbacks and there is > the style of programming involving writing callbacks and registering > them. Unfortunately, in the age when I took my C class, there was no > discussion along these lines. > > Can anyone give clear definition, example, benefits, variations, > origin or citation to a paper where it originated and explained first, > as well as some modern text that does the better than most job of > illustrating it and its applications. When a C function takes as an argument a pointer to another function, the function pointed at is often referred to as a callback function. Examples from the C standard library include qsort() and bsearch(), where the callback function is called in order to determine the relative order of the records processed by those functions. I know nothing about vacall or avcall. I've heard of trampolines in the context of computer programming, but know little about them. For all questions like this, I would recommend starting with wikipedia - it generally does a good job of explaining computer-oriented technical terms like these; if you don't find it there, try google.
[toc] | [prev] | [next] | [standalone]
| From | fmassei@gmail.com |
|---|---|
| Date | 2012-10-25 13:08 -0700 |
| Message-ID | <af118776-83c7-4aef-8edc-01beb10a359a@googlegroups.com> |
| In reply to | #27687 |
On Thursday, October 25, 2012 10:04:16 PM UTC+2, James Kuyper wrote: > On 10/25/2012 03:24 PM, gnuist007@hotmail.com wrote: > > > Dear Programming Gurus, > > > These concepts are rather well talked about .. over the internet and > > usenet, however, I cant find any clear explanation. > > avcall, callback, trampoline, vacall, etc > > I know nothing about vacall or avcall. I've heard of trampolines in the > context of computer programming, but know little about them. > On a multi-processor system, one CPU boots, and the others use a "trampoline" code (usually prepared by the first one) to boot. Ciao!
[toc] | [prev] | [next] | [standalone]
| From | James Kuyper <jameskuyper@verizon.net> |
|---|---|
| Date | 2012-10-25 16:12 -0400 |
| Message-ID | <50899D29.4050604@verizon.net> |
| In reply to | #27688 |
On 10/25/2012 04:08 PM, fmassei@gmail.com wrote: > On Thursday, October 25, 2012 10:04:16 PM UTC+2, James Kuyper wrote: >> On 10/25/2012 03:24 PM, gnuist007@hotmail.com wrote: >> >>> Dear Programming Gurus, >> >>> These concepts are rather well talked about .. over the internet and >>> usenet, however, I cant find any clear explanation. >>> avcall, callback, trampoline, vacall, etc >> >> I know nothing about vacall or avcall. I've heard of trampolines in the >> context of computer programming, but know little about them. >> > > On a multi-processor system, one CPU boots, and the others use a "trampoline" code (usually prepared by the first one) to boot. That's one type of trampoline described at <http://en.wikipedia.org/wiki/Trampoline_%28computing%29> Most of the other types of trampolines described there seem more likely to be relevant to his question that that type.
[toc] | [prev] | [next] | [standalone]
| From | fmassei@gmail.com |
|---|---|
| Date | 2012-10-25 13:23 -0700 |
| Message-ID | <261ad468-a9ad-4170-b118-a293f65fee4c@googlegroups.com> |
| In reply to | #27690 |
On Thursday, October 25, 2012 10:12:30 PM UTC+2, James Kuyper wrote: > On 10/25/2012 04:08 PM, fmassei@gmail.com wrote: > > > On a multi-processor system, one CPU boots, and the others use a "trampoline" code (usually prepared by the first one) to boot. > > That's one type of trampoline described at > <http://en.wikipedia.org/wiki/Trampoline_%28computing%29> > Most of the other types of trampolines described there seem more likely > to be relevant to his question that that type. Curious! I never heard this term used outside the SMP development. There's always something to learn.. Ciao!
[toc] | [prev] | [next] | [standalone]
| From | Joe Pfeiffer <pfeiffer@cs.nmsu.edu> |
|---|---|
| Date | 2012-10-25 20:01 -0600 |
| Message-ID | <1bip9y6lf3.fsf@new-snowball.wb.pfeifferfamily.net> |
| In reply to | #27691 |
fmassei@gmail.com writes: > On Thursday, October 25, 2012 10:12:30 PM UTC+2, James Kuyper wrote: >> On 10/25/2012 04:08 PM, fmassei@gmail.com wrote: >> >> > On a multi-processor system, one CPU boots, and the others use a "trampoline" code (usually prepared by the first one) to boot. >> >> That's one type of trampoline described at >> <http://en.wikipedia.org/wiki/Trampoline_%28computing%29> >> Most of the other types of trampolines described there seem more likely >> to be relevant to his question that that type. > > Curious! I never heard this term used outside the SMP development. There's always something to learn.. Ironically, SMP development is a use I hadn't come across!
[toc] | [prev] | [next] | [standalone]
| From | Gene Wirchenko <genew@ocis.net> |
|---|---|
| Date | 2012-10-25 14:55 -0700 |
| Message-ID | <7ncj88lmdqn62kjmirccuq8soabmaf7it8@4ax.com> |
| In reply to | #27687 |
On Thu, 25 Oct 2012 16:04:10 -0400, James Kuyper
<jameskuyper@verizon.net> wrote:
>On 10/25/2012 03:24 PM, gnuist007@hotmail.com wrote:
>> Dear Programming Gurus,
>>
>> These concepts are rather well talked about .. over the internet and
>> usenet, however, I cant find any clear explanation.
>>
>> avcall, callback, trampoline, vacall, etc
^^^1^^ ^^^^2^^^ ^^^^^3^^^^ ^^^4^^
GIYF!
1) Google for "avcall". For me, it was the first link.
2) Google for "callback". For me, it was the first link.
3) Google for "programming trampoline". For me, it was the first
link.
4) This one is a bit tougher. Noting that avcall got me a .h, I
Googled for "vacall.h". For me, the fourth link is for the vacall(3)
Linux man page.
[snip]
>> Can anyone give clear definition, example, benefits, variations,
>> origin or citation to a paper where it originated and explained first,
>> as well as some modern text that does the better than most job of
>> illustrating it and its applications.
Did you even bother looking first?
I had only heard of two of them and was able to find all four
fairly easily.
>When a C function takes as an argument a pointer to another function,
>the function pointed at is often referred to as a callback function.
>Examples from the C standard library include qsort() and bsearch(),
>where the callback function is called in order to determine the relative
>order of the records processed by those functions.
>
>I know nothing about vacall or avcall. I've heard of trampolines in the
>context of computer programming, but know little about them.
>
>For all questions like this, I would recommend starting with wikipedia -
>it generally does a good job of explaining computer-oriented technical
>terms like these; if you don't find it there, try google.
Agreed about Wikipedia's reliability in this area, but I prefer
to use Google first. One can find out about more groups that way and
even lanaguage standards. If Google returns a Wikipedia link, I will
usually have a look.
Sincerely,
Gene Wirchenko
[toc] | [prev] | [next] | [standalone]
| From | Paavo Helde <myfirstname@osa.pri.ee> |
|---|---|
| Date | 2012-10-25 15:46 -0500 |
| Message-ID | <XnsA0F7F1EF5136Fmyfirstnameosapriee@216.196.109.131> |
| In reply to | #27685 |
gnuist007@hotmail.com wrote in news:dfa26195-ed53-41e7-afb6-6f59d556a154@ 3g2000yqn.googlegroups.com: > Dear Programming Gurus, > > These concepts are rather well talked about .. over the internet and > usenet, however, I cant find any clear explanation. > > avcall, callback, trampoline, vacall, etc > > I looked in a book of C programming, ie k&r and also the rationale for > C, an old copy and could not find any explanation. > > I know that javascript books talk a lot about callbacks and there is > the style of programming involving writing callbacks and registering > them. Unfortunately, in the age when I took my C class, there was no > discussion along these lines. > > Can anyone give clear definition, example, benefits, variations, > origin or citation to a paper where it originated and explained first, > as well as some modern text that does the better than most job of > illustrating it and its applications. I think you included comp.lang.c++ in the posted newsgroups by a mistake. In C++, the callbacks have been mostly replaced by virtual functions (usually declared in abstract base classes). Also the vacall tricks for passing multiple arguments at once are not really needed in C++, you can always pass a suitable container of (possibly variant) arguments. Anyway, in this day and this age, you should look in wikipedia first instead of K&R books. HTH Paavo PS. Followup set to comp.lang.c
[toc] | [prev] | [next] | [standalone]
| From | "James K. Lowden" <jklowden@speakeasy.net> |
|---|---|
| Date | 2012-10-25 18:53 -0400 |
| Message-ID | <20121025185343.c9642838.jklowden@speakeasy.net> |
| In reply to | #27692 |
On Thu, 25 Oct 2012 15:46:59 -0500 Paavo Helde <myfirstname@osa.pri.ee> wrote: > In C++, the callbacks have been mostly replaced by virtual functions In C++, callbacks have been mostly replaced by functors and, more recently, lambdas. FTFY! :-) --jkl
[toc] | [prev] | [next] | [standalone]
| From | Öö Tiib <ootiib@hot.ee> |
|---|---|
| Date | 2012-10-26 13:18 -0700 |
| Message-ID | <8682c5f6-35b5-4e6e-b6ae-a6976126281c@googlegroups.com> |
| In reply to | #27700 |
On Friday, 26 October 2012 01:53:44 UTC+3, James K. Lowden wrote: > On Thu, 25 Oct 2012 15:46:59 -0500 > Paavo Helde <myfirstname@osa.pri.ee> wrote: > > > In C++, the callbacks have been mostly replaced by virtual functions > > In C++, callbacks have been mostly replaced by functors and, more > recently, lambdas. Callbacks and virtual functions can not carry any state so you have usually to provide some "context pointer" or "interface pointer" together with those. Functors and lambdas have usually both function and state embedded into them. So those are (or can be) more advanced beast than callback.
[toc] | [prev] | [next] | [standalone]
| From | fmassei@gmail.com |
|---|---|
| Date | 2012-10-26 13:33 -0700 |
| Message-ID | <facde234-35bb-4f86-a02e-1219d6d393c4@googlegroups.com> |
| In reply to | #27735 |
On Friday, October 26, 2012 10:18:23 PM UTC+2, Öö Tiib wrote: > On Friday, 26 October 2012 01:53:44 UTC+3, James K. Lowden wrote: > > On Thu, 25 Oct 2012 15:46:59 -0500 > > Paavo Helde <myfirstname@osa.pri.ee> wrote: > > > > In C++, the callbacks have been mostly replaced by virtual functions > > > In C++, callbacks have been mostly replaced by functors and, more > > recently, lambdas. > > Callbacks and virtual functions can not carry any state so you have usually to > provide some "context pointer" or "interface pointer" together with those. > > Functors and lambdas have usually both function and state embedded into them. > So those are (or can be) more advanced beast than callback. Maybe I'm wrong (or just pedant) but aren't "callbacks" and "functors/lambdas" concepts belonging to different levels? ;-) For example, I could write a lambda function where a callback is needed (this is actually pretty common in C#/C mixtures). Ciao!
[toc] | [prev] | [next] | [standalone]
| From | Cortez <relativeflux@hotmail.co.uk> |
|---|---|
| Date | 2012-10-25 13:47 -0700 |
| Message-ID | <6f78f4b6-8a76-4b3e-afc3-a2f2d35ebd83@s12g2000vbw.googlegroups.com> |
| In reply to | #27685 |
On Oct 25, 8:24 pm, gnuist...@hotmail.com wrote: > Dear Programming Gurus, > > These concepts are rather well talked about .. over the internet and > usenet, however, I cant find any clear explanation. > > avcall, callback, trampoline, vacall, etc > > I looked in a book of C programming, ie k&r and also the rationale for > C, an old copy and could not find any explanation. > > I know that javascript books talk a lot about callbacks and there is > the style of programming involving writing callbacks and registering > them. Unfortunately, in the age when I took my C class, there was no > discussion along these lines. > > Can anyone give clear definition, example, benefits, variations, > origin or citation to a paper where it originated and explained first, > as well as some modern text that does the better than most job of > illustrating it and its applications. There's a trampoline function in Clojure, but I really don't know much about it, or whether it's even the same thing as you're talking about. This article seems to suggest it is: http://pramode.net/clojure/2010/05/08/clojure-trampoline/
[toc] | [prev] | [next] | [standalone]
| From | Joe Pfeiffer <pfeiffer@cs.nmsu.edu> |
|---|---|
| Date | 2012-10-25 20:18 -0600 |
| Message-ID | <1ba9va6kmw.fsf@new-snowball.wb.pfeifferfamily.net> |
| In reply to | #27685 |
gnuist007@hotmail.com writes: > Dear Programming Gurus, > > These concepts are rather well talked about .. over the internet and > usenet, however, I cant find any clear explanation. > > avcall, callback, trampoline, vacall, etc Speaking only for myself, I found the idea of a 'callback' one that was really easy to describe, but really hard to understand for a long time. I see some other posters have already pointed you at google on this one, but I'll give it a shot anyway. The big thing about callbacks is that everything you know about writing a program is turned completely on its head. It sounds like you may have learned C when I did (or at any rate before these newfangles concepts came about). If so, you're used to the idea that your main() is basically in control, and calls functions you write, more or less one at a time in an order you specify. So first you call a function (or some functions) that read your input; then you call a function that gets some work done; then you call a function that writes your output. It's likely your code isn't that clean in real life; you probably actually read a little bit of input, do a little bit of work, write a little bit of output, lather rinse repeat. Doesn't matter, you're still in control of when your functions get called. For callback-based programming, forget all that. Flush it. There are areas where a completely different paradigm is used. A good example of one of these areas is writing a GUI interface. The big thing about a GUI interface is that you don't have control of the order in which input arrives, and you need to do something about whatever the crazy user does. In this world, somebody else writes something called an "event loop". The event loop just sits out there waiting for input (maybe a button click, maybe information that you need to redraw your window, maybe a timeout, maybe something else), and when the input happens the event loop code calls a function you wrote to handle that particular input. Your function is called a 'callback'. So that's the idea. You write a function to handle the user clicking the 'OK' button. You write a function to handle a window resize event. You write a function to... whatever. You pass a pointer to your function to the event loop code (this is called 'registering' your callback), and just sit back and wait for your code to be called. Another application of callbacks is in FUSE (Filesystem in User SpacE) filesystems. I will somewhat immodestly suggest that a tutorial on FUSE that you can find at http://www.cs.nmsu.edu/~pfeiffer/fuse-tutorial/ may help you.
[toc] | [prev] | [next] | [standalone]
| From | gnuist007@hotmail.com |
|---|---|
| Date | 2012-10-26 10:11 -0700 |
| Message-ID | <02c059a9-268f-4ae4-bb1c-737c6bc4268d@l12g2000vbj.googlegroups.com> |
| In reply to | #27706 |
On Oct 25, 7:18 pm, Joe Pfeiffer <pfeif...@cs.nmsu.edu> wrote: > gnuist...@hotmail.com writes: > > Dear Programming Gurus, > > > These concepts are rather well talked about .. over the internet and > > usenet, however, I cant find any clear explanation. > > > avcall, callback, trampoline, vacall, etc > > Speaking only for myself, I found the idea of a 'callback' one that was > really easy to describe, but really hard to understand for a long time. > I see some other posters have already pointed you at google on this one, > but I'll give it a shot anyway. > > The big thing about callbacks is that everything you know about writing > a program is turned completely on its head. It sounds like you may have > learned C when I did (or at any rate before these newfangles concepts > came about). If so, you're used to the idea that your main() is > basically in control, and calls functions you write, more or less one at > a time in an order you specify. So first you call a function (or some > functions) that read your input; then you call a function that gets some > work done; then you call a function that writes your output. It's > likely your code isn't that clean in real life; you probably actually > read a little bit of input, do a little bit of work, write a little bit > of output, lather rinse repeat. Doesn't matter, you're still in control > of when your functions get called. > > For callback-based programming, forget all that. Flush it. > > There are areas where a completely different paradigm is used. A good example > of one of these areas is writing a GUI interface. The big thing about a > GUI interface is that you don't have control of the order in which input > arrives, and you need to do something about whatever the crazy user > does. In this world, somebody else writes something called an "event > loop". The event loop just sits out there waiting for input (maybe a > button click, maybe information that you need to redraw your window, > maybe a timeout, maybe something else), and when the input happens the > event loop code calls a function you wrote to handle that particular > input. Your function is called a 'callback'. > > So that's the idea. You write a function to handle the user clicking > the 'OK' button. You write a function to handle a window resize event. > You write a function to... whatever. You pass a pointer to your > function to the event loop code (this is called 'registering' your > callback), and just sit back and wait for your code to be called. I think, the above paras were what I was wanting as a reply although all replies were useful. What I want to consolidate is really some good and illustrative toy examples. Can you cook any or have a link to some that you have whetted are good? > Another application of callbacks is in FUSE (Filesystem in User SpacE) > filesystems. I will somewhat immodestly suggest that a tutorial on FUSE > that you can find athttp://www.cs.nmsu.edu/~pfeiffer/fuse-tutorial/may > help you. I come to this after you give some examples of the first idea.
[toc] | [prev] | [next] | [standalone]
| From | Jorgen Grahn <grahn+nntp@snipabacken.se> |
|---|---|
| Date | 2012-10-27 18:17 +0000 |
| Message-ID | <slrnk8o9a5.1d3.grahn+nntp@frailea.sa.invalid> |
| In reply to | #27706 |
[Trimmed the newsgroups a bit ... probably not enough] On Fri, 2012-10-26, Joe Pfeiffer wrote: > gnuist007@hotmail.com writes: > >> Dear Programming Gurus, >> >> These concepts are rather well talked about .. over the internet and >> usenet, however, I cant find any clear explanation. >> >> avcall, callback, trampoline, vacall, etc > > Speaking only for myself, I found the idea of a 'callback' one that was > really easy to describe, but really hard to understand for a long time. > I see some other posters have already pointed you at google on this one, > but I'll give it a shot anyway. [snip] > For callback-based programming, forget all that. Flush it. I think you're exaggerating a bit here. But sure, callbacks are a bit funny, and worth thinking about before trying to use them. > There are areas where a completely different paradigm is used. A good example > of one of these areas is writing a GUI interface. The big thing about a > GUI interface is that you don't have control of the order in which input > arrives, and you need to do something about whatever the crazy user > does. In this world, somebody else writes something called an "event > loop". It seems to be very popular to design GUI frameworks that way, but there is nothing that /forces/ them to do it. The fact that a GUI application is (at leasr partly) driven by user input doesn't mean you have to resort to callbacks. Of course if a certain GUI framework forces you to use callbacks, you have to do it. [snip] /Jorgen -- // Jorgen Grahn <grahn@ Oo o. . . \X/ snipabacken.se> O o .
[toc] | [prev] | [next] | [standalone]
| From | Joe Pfeiffer <pfeiffer@cs.nmsu.edu> |
|---|---|
| Date | 2012-10-27 21:35 -0600 |
| Message-ID | <1bfw4zl148.fsf@new-snowball.wb.pfeifferfamily.net> |
| In reply to | #27768 |
Jorgen Grahn <grahn+nntp@snipabacken.se> writes: > [Trimmed the newsgroups a bit ... probably not enough] > > On Fri, 2012-10-26, Joe Pfeiffer wrote: >> gnuist007@hotmail.com writes: >> >>> Dear Programming Gurus, >>> >>> These concepts are rather well talked about .. over the internet and >>> usenet, however, I cant find any clear explanation. >>> >>> avcall, callback, trampoline, vacall, etc >> >> Speaking only for myself, I found the idea of a 'callback' one that was >> really easy to describe, but really hard to understand for a long time. >> I see some other posters have already pointed you at google on this one, >> but I'll give it a shot anyway. > > [snip] > >> For callback-based programming, forget all that. Flush it. > > I think you're exaggerating a bit here. But sure, callbacks are a bit > funny, and worth thinking about before trying to use them. I don't think I'm exaggerating at all. This is one of those areas where your previous intuitions about how a program fits together will do more harm than good, and a necessary first step is to forget your previous intuitions. >> There are areas where a completely different paradigm is used. A good example >> of one of these areas is writing a GUI interface. The big thing about a >> GUI interface is that you don't have control of the order in which input >> arrives, and you need to do something about whatever the crazy user >> does. In this world, somebody else writes something called an "event >> loop". > > It seems to be very popular to design GUI frameworks that way, but > there is nothing that /forces/ them to do it. The fact that a GUI > application is (at leasr partly) driven by user input doesn't mean you > have to resort to callbacks. > > Of course if a certain GUI framework forces you to use callbacks, you > have to do it. And since the context of my post was somebody asking for help understanding callbacks, that is the class of GUI program I described.
[toc] | [prev] | [next] | [standalone]
| From | Jorgen Grahn <grahn+nntp@snipabacken.se> |
|---|---|
| Date | 2012-10-29 12:38 +0000 |
| Message-ID | <slrnk8su57.1d3.grahn+nntp@frailea.sa.invalid> |
| In reply to | #27787 |
On Sun, 2012-10-28, Joe Pfeiffer wrote: > Jorgen Grahn <grahn+nntp@snipabacken.se> writes: > >> [Trimmed the newsgroups a bit ... probably not enough] >> >> On Fri, 2012-10-26, Joe Pfeiffer wrote: >>> gnuist007@hotmail.com writes: >>> >>>> Dear Programming Gurus, >>>> >>>> These concepts are rather well talked about .. over the internet and >>>> usenet, however, I cant find any clear explanation. >>>> >>>> avcall, callback, trampoline, vacall, etc >>> >>> Speaking only for myself, I found the idea of a 'callback' one that was >>> really easy to describe, but really hard to understand for a long time. >>> I see some other posters have already pointed you at google on this one, >>> but I'll give it a shot anyway. >> >> [snip] >> >>> For callback-based programming, forget all that. Flush it. >> >> I think you're exaggerating a bit here. But sure, callbacks are a bit >> funny, and worth thinking about before trying to use them. > > I don't think I'm exaggerating at all. This is one of those areas where > your previous intuitions about how a program fits together will do more > harm than good, and a necessary first step is to forget your previous > intuitions. Then we disagree slightly. And that's fine -- the OP has seen two opinions, and can make up his own mind. Perhaps I'm overly sensitive to "forget everything you think you know!" messages. /Jorgen -- // Jorgen Grahn <grahn@ Oo o. . . \X/ snipabacken.se> O o .
[toc] | [prev] | [next] | [standalone]
| From | "Pascal J. Bourguignon" <pjb@informatimago.com> |
|---|---|
| Date | 2012-10-28 18:56 +0100 |
| Message-ID | <87r4oiiiq0.fsf@informatimago.com> |
| In reply to | #27706 |
Joe Pfeiffer <pfeiffer@cs.nmsu.edu> writes:
> For callback-based programming, forget all that. Flush it.
>
> There are areas where a completely different paradigm is used. A good example
> of one of these areas is writing a GUI interface. The big thing about a
> GUI interface is that you don't have control of the order in which input
> arrives, and you need to do something about whatever the crazy user
> does. In this world, somebody else writes something called an "event
> loop". The event loop just sits out there waiting for input (maybe a
> button click, maybe information that you need to redraw your window,
> maybe a timeout, maybe something else), and when the input happens the
> event loop code calls a function you wrote to handle that particular
> input. Your function is called a 'callback'.
Yes, but in general, there is still this direct and simple flow of
control: a function calls another function, and so on.
A callback is just a function that is given to some module, to be called
when the module needs to call it. This is a way to parameterize or
customize that module.
(defun my-callback (data)
(format t "Received ~A~%" data))
(defun receive-loop (data-callback)
(loop
:for line = (progn (format *query-io* "> ")
(finish-output *query-io*)
(read-line *query-io* nil nil))
:while (and line (plusp (length line)))
:do (funcall data-callback line)))
cl-user> (receive-loop 'my-callback)
> Hello
Received Hello
> World
Received World
>
nil
cl-user>
And then you can use the receive-loop module with a different callback,
making it do something else:
cl-user> (let ((c 0))
(receive-loop (lambda (data) (incf c (parse-integer data))))
c)
> 42
> 33
> 101
>
176
cl-user>
Now, there's another situation where you really don't know WHEN the
callback is called, it's when the module calling it uses threads, and
calls your callback function at "random" times, possibly in another
thread, or perhaps while handling a unix signal. In this situation,
there are a lot of technicalities to fulfill for calbacks.
But the in usual case, there's no complexity involved.
--
__Pascal Bourguignon__
http://www.informatimago.com
[toc] | [prev] | [next] | [standalone]
| From | Rivka Miller <rivkaumiller@gmail.com> |
|---|---|
| Date | 2012-11-05 16:28 -0800 |
| Message-ID | <4ccb20b3-eac0-4959-b330-5001558126b7@l18g2000vbv.googlegroups.com> |
| In reply to | #27706 |
On Oct 25, 6:18 pm, Joe Pfeiffer <pfeif...@cs.nmsu.edu> wrote: > gnuist...@hotmail.com writes: > > Dear Programming Gurus, > > > These concepts are rather well talked about .. over the internet and > > usenet, however, I cant find any clear explanation. > > > avcall, callback, trampoline, vacall, etc I am a newbie, but let me hazard a reply from what little I know. > Speaking only for myself, I found the idea of a 'callback' one that was > really easy to describe, but really hard to understand for a long time. > I see some other posters have already pointed you at google on this one, > but I'll give it a shot anyway. I think the OP wrote in a rather nice way, going back to the original book on C programming. Even the book by Kernighan and Pike on the Unix does not touch any of these concepts. > The big thing about callbacks is that everything you know about writing > a program is turned completely on its head. It sounds like you may have > learned C when I did (or at any rate before these newfangles concepts > came about). If so, you're used to the idea that your main() is > basically in control, and calls functions you write, more or less one at > a time in an order you specify. So first you call a function (or some > functions) that read your input; then you call a function that gets some > work done; then you call a function that writes your output. It's > likely your code isn't that clean in real life; you probably actually > read a little bit of input, do a little bit of work, write a little bit > of output, lather rinse repeat. Doesn't matter, you're still in control > of when your functions get called. > > For callback-based programming, forget all that. Flush it. > > There are areas where a completely different paradigm is used. A good example > of one of these areas is writing a GUI interface. The big thing about a > GUI interface is that you don't have control of the order in which input > arrives, and you need to do something about whatever the crazy user > does. In this world, somebody else writes something called an "event > loop". The event loop just sits out there waiting for input (maybe a > button click, maybe information that you need to redraw your window, > maybe a timeout, maybe something else), and when the input happens the > event loop code calls a function you wrote to handle that particular > input. Your function is called a 'callback'. > > So that's the idea. You write a function to handle the user clicking > the 'OK' button. You write a function to handle a window resize event. > You write a function to... whatever. You pass a pointer to your > function to the event loop code (this is called 'registering' your > callback), and just sit back and wait for your code to be called. As Joe Pfeiffer said that this has to do with a very different paradigm. I like Joe's reply as he tries to develop a good reply from basics. Those who replied did not seem to add much to it - atleast from my point of view. And a newbie like the OP would probably be confused on this subject. I have a little pedestrian knowledge of the event drive programming. Perhaps, they would have taken Joe's discussion and developed it further. For event-driven programming, you have to start with the concept of a finite state machine FSM. There are a few variations, Mealy and Moore machines. You can also factorize out the states according to alternative, concurrency and inheritance. Most often, one sees callbacks when there are javascript code snippets sent by the server machine to the client machine browser for calling back if it needs something. But the callbacks can also be limited to a single machine with multiple threads or processes running and able to call each other via callbacks - I dont know how, but somehow. Perhaps, someone would take a simple pictorial diagram of an interesting FSM and translate it into a complete code involving callbacks - and comparing with the other paradigm if that can also be done. Or atleast, show how a single transition can be converted to it. An example of GUI might be worth considering. R > Another application of callbacks is in FUSE (Filesystem in User SpacE) > filesystems. I will somewhat immodestly suggest that a tutorial on FUSE > that you can find athttp://www.cs.nmsu.edu/~pfeiffer/fuse-tutorial/may > help you.
[toc] | [prev] | [next] | [standalone]
| From | Les Cargill <lcargill99@comcast.com> |
|---|---|
| Date | 2012-10-26 07:27 -0500 |
| Message-ID | <k6dvjn$r9j$1@dont-email.me> |
| In reply to | #27685 |
gnuist007@hotmail.com wrote:
> Dear Programming Gurus,
>
> These concepts are rather well talked about .. over the internet and
> usenet, however, I cant find any clear explanation.
>
> avcall, callback, trampoline, vacall, etc
>
> I looked in a book of C programming, ie k&r and also the rationale for
> C, an old copy and could not find any explanation.
>
> I know that javascript books talk a lot about callbacks and there is
> the style of programming involving writing callbacks and registering
> them. Unfortunately, in the age when I took my C class, there was no
> discussion along these lines.
>
> Can anyone give clear definition, example, benefits, variations,
> origin or citation to a paper where it originated and explained first,
> as well as some modern text that does the better than most job of
> illustrating it and its applications.
>
"Callbacks" are a method of storing pointers to functions
and exploiting them.
I'm answering from comp.lang.c so one thing I would start with is to
learn the concept of an ioctl(). It's one of the oldest ways to
do this sort of thing. Just google for "device driver programming in
linux" and follow some of the simpler examples. ioctl() is a pattern
that occurs quite frequently, in and out of kernel/driver
development.
After that, just do plain old callbacks in 'C' - declare...
//a typedef
typedef void (*cbtype)(char *);
// an array of them
cbtype cbtab[3];
// an initializer
void set_cb(cbtype a,int idx)
{
...
}
// and reference the callbacks
void thing(char *s)
{
...
}
...
set_cb(thing,2);
cbtab[2]("Calling Elvis");
--
Les Cargill
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | comp.lang.c
csiph-web