Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   avcall, callback, trampoline, vacall, etc (http://www.velocityreviews.com/forums/t953911-avcall-callback-trampoline-vacall-etc.html)

gnuist007@hotmail.com 10-25-2012 07:24 PM

avcall, callback, trampoline, vacall, etc
 
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.


James Kuyper 10-25-2012 08:04 PM

Re: avcall, callback, trampoline, vacall, etc
 
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.


fmassei@gmail.com 10-25-2012 08:08 PM

Re: avcall, callback, trampoline, vacall, etc
 
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!

James Kuyper 10-25-2012 08:12 PM

Re: avcall, callback, trampoline, vacall, etc
 
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.

fmassei@gmail.com 10-25-2012 08:23 PM

Re: avcall, callback, trampoline, vacall, etc
 
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!

Cortez 10-25-2012 08:47 PM

Re: avcall, callback, trampoline, vacall, etc
 
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/0...re-trampoline/

Gene Wirchenko 10-25-2012 09:55 PM

Re: avcall, callback, trampoline, vacall, etc
 
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

Joe Pfeiffer 10-26-2012 02:01 AM

Re: avcall, callback, trampoline, vacall, etc
 
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!

Joe Pfeiffer 10-26-2012 02:18 AM

Re: avcall, callback, trampoline, vacall, etc
 
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.

Les Cargill 10-26-2012 12:27 PM

Re: avcall, callback, trampoline, vacall, etc
 
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


All times are GMT. The time now is 05:32 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.