Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   callback functions (http://www.velocityreviews.com/forums/t439279-callback-functions.html)

DevarajA 09-03-2005 10:20 AM

callback functions
 
Is it possible to write a function that, once called, is executed
together with the caller without stopping it? I've seen such functions
in windows programming, using CALLBACK qualifier before the function
name (is it a macro?). Now I would like to know if this could be
possible in standard C, maybe using some tricks. And going a little ot..
what other non-standard ways to do that do you know?

--
Devaraja (Xdevaraja87^gmail^c0mX)
Linux Registerd User #338167
http://counter.li.org

Emmanuel Delahaye 09-03-2005 01:53 PM

Re: callback functions
 
DevarajA wrote on 03/09/05 :
> Is it possible to write a function that, once called, is executed together
> with the caller without stopping it? I've seen such functions in windows
> programming, using CALLBACK qualifier before the function name (is it a
> macro?). Now I would like to know if this could be possible in standard C,
> maybe using some tricks. And going a little ot.. what other non-standard ways
> to do that do you know?


Callbacks have nothing to do with concurrent ('executed together ')
functions. They are just user functions called by some lower level
function (system, library...) See the standard qsort() function and its
'compare' callback.

If you want concurrent (well, sort of) execution, you want processes or
threads. Theses are beyond the scope of the C-language. Ask a newsgroup
dedicated to your system.

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

"Clearly your code does not meet the original spec."
"You are sentenced to 30 lashes with a wet noodle."
-- Jerry Coffin in a.l.c.c++



John Smith 09-03-2005 03:58 PM

Re: callback functions
 
Emmanuel Delahaye wrote:
> DevarajA wrote on 03/09/05 :
>
>> Is it possible to write a function that, once called, is executed
>> together with the caller without stopping it? I've seen such functions
>> in windows programming, using CALLBACK qualifier before the function
>> name (is it a macro?). Now I would like to know if this could be
>> possible in standard C, maybe using some tricks. And going a little
>> ot.. what other non-standard ways to do that do you know?

>
>
> Callbacks have nothing to do with concurrent ('executed together ')
> functions. They are just user functions called by some lower level
> function (system, library...) See the standard qsort() function and its
> 'compare' callback.
>
> If you want concurrent (well, sort of) execution, you want processes or
> threads. Theses are beyond the scope of the C-language. Ask a newsgroup
> dedicated to your system.
>


You define a callback function as a user function called by a
lower level function, but the example you give seems to
illustrate the opposite case, that is, one in which a user
function calls a lower level function. qsort always calls
compare, never the other way round. Have I misunderstood?

JS


Emmanuel Delahaye 09-03-2005 04:50 PM

Re: callback functions
 
John Smith wrote on 03/09/05 :
> You define a callback function as a user function called by a lower level
> function, but the example you give seems to illustrate the opposite case,


I don't think so.

> that is, one in which a user function calls a lower level function. qsort
> always calls compare, never the other way round. Have I misunderstood?


This is exactly how the compare() function is called : by qsort() which
is a library function.

user code ------|--> qsort() (RTL code)
compare() <---|---

The compare() function belongs to the user's world.

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

"There are 10 types of people in the world today;
those that understand binary, and those that dont."



DevarajA 09-03-2005 05:12 PM

Re: callback functions
 
Emmanuel Delahaye ha scritto:
> John Smith wrote on 03/09/05 :
>
>> You define a callback function as a user function called by a lower
>> level function, but the example you give seems to illustrate the
>> opposite case,

>
>
> I don't think so.
>
>> that is, one in which a user function calls a lower level function.
>> qsort always calls compare, never the other way round. Have I
>> misunderstood?

>
>
> This is exactly how the compare() function is called : by qsort() which
> is a library function.
>
> user code ------|--> qsort() (RTL code)
> compare() <---|---


What do you mean by RTL code?

--
Devaraja (Xdevaraja87^gmail^c0mX)
Linux Registerd User #338167
http://counter.li.org

Alexei A. Frounze 09-03-2005 05:51 PM

Re: callback functions
 
"DevarajA" <no@spam.com> wrote in message
news:fQkSe.15104$4g5.979569@news4.tin.it...
....
> What do you mean by RTL code?


Run Time Library.

Alex




All times are GMT. The time now is 11:31 PM.

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