-----Original Message-----
From: shashi kiran [mailto:kiran_vee@yahoo.com]
Sent: Wed 9/15/2004 8:56 AM
To: Vijay Zanvar (WT01 - TELECOM SOLUTIONS)
Cc:
Subject: About call back
Hello Shashi Kiran,
> Hai Vijai,
>
> I am really happy coz I got ur email ID , all this days I kept mailing to
> that hotpop email r u still using that.
>
Good that something made you happy. Yes, I have left using hotpop for
the time being.
> Congrats for joining Wipro, Wipro will achieve some new heights I hope.
>
Thanks for your wishes!
> Coming to my Question:
> Pls explain me the call back mechanism, is it we can use that instead of THREADS ?
>
My knowledge about thread is almost near to zero. But as little I know
of threads, callback mechanism is almost always used along with threads,
at least, with the creation of threads.
I can not think of defining callback mechanism, but it is best understood
with an example. Consider three functions a(), b() and c(). We will
assign roles to these funtions as follows:
a() A control function which, perhaps, interacts with the user(s) in
some way.
b() A function which processes defined operations on a certain data-
structure without knowing what the data-structure is.
c() A function which knows and processes the data-structure.
Here is one possible snap shot:
typedef /* something */ data_s;
void
c ( data_s *p )
{
/* do something */
}
void
b ( void (*ptr)(data_s*) )
{
data_s *p = ... ; /* initialize data-structure */
...
(*ptr)(p); /* process the data-structure */
...
}
void
a ( void )
{
...
b ( c ); /* process the data-structure using c() */
...
}
The advantage of this mechanism is that it provides a level of indirection
to the function b() which is helpful to make it data independent. If you
were to implement the same logic to process different type of data-structures,
then the code size increases creating maintanance problems.
One example of callback mechanism is the standard qsort(3) function:
#include
void qsort(void *base, size_t nel, size_t width, int
(*compar)(const void *, const void *));
The sorting becomes independent of type of the data, because COMPAR provides
a level of indirection.
In simple words, we can say that the callback mechanism involves a function
which is passed the address of another function; and the called function
calls the passed funciton.
Perhaps, a person experienced in using threads can enlighten us as how
the callback mechanism and threads are related.
> last but no least
> Mail me the jaisimhas Email ID:
>
jayasimha_a at rediffmail.com
> Regards
> Kiran
>
               (
geocities.com/vijoeyz/faq)                   (
geocities.com/vijoeyz)