call back function

what is a call back function?
if possible an example aswell
thanks in advance
I am in relearning process, sorry if i make a mistake

Comments

  • A callback function is a user-defined function that is called by the operative system, not the programmer. These are particulary common in Windows programming, but also in multi-threaded programs.
  • let me see if i understood

    if i have some c++ code and using unix system a call back function would be a system call.

    code is more like pseudo-code
    [code]
    #include
    using namespace std;

    int main{

    system("echo cat");//This would be a call-back function

    return 0;
    }

    [/code]
    I am in relearning process, sorry if i make a mistake
  • No, that example is the programmer calling a function.

    An example of a callback function could be a timer in the OS:

    [code]int main()
    {
    create timer that will become active after 10 seconds

    for(;;)
    {
    /* main program */
    }
    }

    void timer_callback_function (void)
    {
    /* this function is called by the OS after 10 seconds,
    the programmer never calls it */
    }[/code]

    If you are familiar with hardware-related programming, a callback function works exactly as an interrupt.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories