callback functions

Discussion in 'C Programming' started by DevarajA, Sep 3, 2005.

  1. DevarajA

    DevarajA Guest

    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
    DevarajA, Sep 3, 2005
    #1
    1. Advertising

  2. 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++
    Emmanuel Delahaye, Sep 3, 2005
    #2
    1. Advertising

  3. DevarajA

    John Smith Guest

    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
    John Smith, Sep 3, 2005
    #3
  4. 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."
    Emmanuel Delahaye, Sep 3, 2005
    #4
  5. DevarajA

    DevarajA Guest

    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
    DevarajA, Sep 3, 2005
    #5
  6. "DevarajA" <> wrote in message
    news:fQkSe.15104$...
    ....
    > What do you mean by RTL code?


    Run Time Library.

    Alex
    Alexei A. Frounze, Sep 3, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. exquisitus
    Replies:
    23
    Views:
    47,537
    Andrew McDonagh
    Feb 28, 2005
  2. Pratik

    Callback functions

    Pratik, Jun 15, 2004, in forum: C++
    Replies:
    5
    Views:
    464
    E. Robert Tisdale
    Jun 15, 2004
  3. Xiangliang Meng
    Replies:
    1
    Views:
    1,591
    Victor Bazarov
    Jun 21, 2004
  4. cadull

    Member Callback Functions

    cadull, May 6, 2005, in forum: C++
    Replies:
    1
    Views:
    483
    cadull
    May 6, 2005
  5. Replies:
    11
    Views:
    962
    Richard Herring
    Jun 7, 2005
Loading...

Share This Page