I am looking for some comprehensive tutorials on how to write call
back functions in C. Can anyone help me?
Write a callback function in the same way you write
any other function. There is nothing "different" about a
callback function, nothing at all. It's just a function.
On Thu, 28 Jun 2007 02:57:06 -0700, "sameer.oak@gma il.com"
<sameer.oak@gma il.comwrote:
>I am looking for some comprehensive tutorials on how to write call
>back functions in C. Can anyone help me?
>
It depends on who is calling your function and what you want the
function to do for them. Probably the simplest example is the compare
function passed to qsort. There should be at least one example in
your reference which will show you how to obtain the arguments passed
as generic pointers and return a result. Anything else will require
more detail from you.
>I am looking for some comprehensive tutorials on how to write call
>back functions in C. Can anyone help me?
>
Write a callback function in the same way you write
any other function. There is nothing "different" about a
callback function, nothing at all. It's just a function.
>
That is to say, the "callback" part is how the function is used, not how
it is defined.
--
clvrmnky <mailto:spamtra p@clevermonkey. org>
Direct replies will be blacklisted. Replace "spamtrap" with my name to
contact me directly.
>>I am looking for some comprehensive tutorials on how to write call
>>back functions in C. Can anyone help me?
> Write a callback function in the same way you write
>any other function. There is nothing "different" about a
>callback function, nothing at all. It's just a function.
>That is to say, the "callback" part is how the function is used, not how
>it is defined.
Not entirely. The way that it is used has implications for its
definition.
Callback functions are unusual in that their types are generally
specified by a library, but their definitions are written by the user,
and some or all of their arguments are passed in by the user. As a
result, callbacks are commonly defined to take void * arguments
(allowing the user some flexibility in the values that can be passed)
where a similar function not used as a callback would probably take
more specifically typed arguments.
-- Richard
--
"Considerat ion shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
>>>I am looking for some comprehensive tutorials on how to write call
>>>back functions in C. Can anyone help me?
>
>> Write a callback function in the same way you write
>>any other function. There is nothing "different" about a
>>callback function, nothing at all. It's just a function.
>
>That is to say, the "callback" part is how the function is used, not how
>it is defined.
>
Not entirely. The way that it is used has implications for its
definition.
>
Callback functions are unusual in that their types are generally
specified by a library, but their definitions are written by the user,
and some or all of their arguments are passed in by the user. As a
result, callbacks are commonly defined to take void * arguments
(allowing the user some flexibility in the values that can be passed)
where a similar function not used as a callback would probably take
more specifically typed arguments.
>
I see your point. Upon consideration, I realize I have experience only
with two varieties of callback:
- An function passed to a module to facilitate code generalization.
e.g., a way to provide a function to a module that updates a UI by
calling back to an API that has no knowledge of the UI specifics.
- A generic library call, such as a data structure deletion function, or
the classic sorting function.
In the first case we generally know what sorts of args it will take, and
what type (it does in the legacy code I maintain, anyway). It is just
who is running it, and how exactly they will use it that is unknown to
the provider -- the provider just provides the data in a known format.
In the latter we have to provide a more generic interface.
I'm more familiar with the former, but recently had to implement a map
for a public API, which required a generic dispose() function to be used
as a callback. I'd forgotten the subtleties.
--
clvrmnky <mailto:spamtra p@clevermonkey. org>
Direct replies will be blacklisted. Replace "spamtrap" with my name to
contact me directly.
>>>I am looking for some comprehensive tutorials on how to write call
>>>back functions in C. Can anyone help me?
>
>> Write a callback function in the same way you write
>>any other function. There is nothing "different" about a
>>callback function, nothing at all. It's just a function.
>
>That is to say, the "callback" part is how the function is used, not how
>it is defined.
>
Not entirely. The way that it is used has implications for its
definition.
>
Callback functions are unusual in that their types are generally
specified by a library, but their definitions are written by the user,
[...]
Hmmm: Would you describe main() as a callback function?
>>>>I am looking for some comprehensive tutorials on how to write call
>>>>back functions in C. Can anyone help me?
>>
>>> Write a callback function in the same way you write
>>>any other function. There is nothing "different" about a
>>>callback function, nothing at all. It's just a function.
>>
>>That is to say, the "callback" part is how the function is used, not how
>>it is defined.
>>
>Not entirely. The way that it is used has implications for its
>definition.
>>
>Callback functions are unusual in that their types are generally
>specified by a library, but their definitions are written by the user,
>[...]
>
Hmmm: Would you describe main() as a callback function?
>
:-)
>
>
"Eric Sosman" <esosman@acm-dot-org.invalidwrot e in message
news:Cr2dnXv8fJ z6IhjbnZ2dnUVZ_ hSdnZ2d@comcast .com...
>Richard Tobin wrote:
>>In article <XsRgi.15474$13 .8323@nnrp.ca.m ci.com!nnrp1.uu net.ca>,
>>Clever Monkey <spamtrap@cleve rmonkey.org.INV ALIDwrote:
>>>
>>>>>I am looking for some comprehensive tutorials on how to write call
>>>>>back functions in C. Can anyone help me?
>>>
>>>> Write a callback function in the same way you write
>>>>any other function. There is nothing "different" about a
>>>>callback function, nothing at all. It's just a function.
>>>
>>>That is to say, the "callback" part is how the function is used, not
>>>how it is defined.
>>>
>>Not entirely. The way that it is used has implications for its
>>definition.
>>>
>>Callback functions are unusual in that their types are generally
>>specified by a library, but their definitions are written by the user,
>>[...]
>>
> Hmmm: Would you describe main() as a callback function?
>>
> :-)
>>
Yes. The shell calls it.
That is not always true and in any case does not make it a callback.
However, Richard did not say that the aspects he was specifying were
unique to callbacks.
--
Flash Gordon
Comment