Correct files for declaration and definition for callback functions

Discussion in 'C Programming' started by Chris Bore, Dec 7, 2006.

  1. Chris Bore

    Chris Bore Guest

    If I have a self-contained server component, that specifies callback
    functions, then would it be good practice for:

    1) the server component itself to provide a header file with the
    callback function declarations
    2) the client to implement the function definitions

    In this way the server owns the interface (usage, through the
    declaration) but the client is responsible for implementation (through
    the definition). There is some checking, by (server's) declaration
    against (client's) implementation, that the implementation at least
    matches the function's declaration.

    I have not seen this separation and defined ownership in code that I
    have studied, but it seems to me that it should be so. I expected to
    find this documented in texts but have not so far found this. It seems
    obvious but is not apparently done. I'd value any comments or examples
    of how it is done in good practice.

    Thanks,

    Chris
    Chris Bore, Dec 7, 2006
    #1
    1. Advertising

  2. Chris Bore

    CBFalconer Guest

    Chris Bore wrote:
    >
    > If I have a self-contained server component, that specifies callback
    > functions, then would it be good practice for:
    >

    .... snip ...
    >
    > I have not seen this separation and defined ownership in code that I
    > have studied, but it seems to me that it should be so. I expected to
    > find this documented in texts but have not so far found this. It seems
    > obvious but is not apparently done. I'd value any comments or examples
    > of how it is done in good practice.


    Take a look at the way hashlib defines and uses the necessary
    auxiliary functions. It is all spelled out in hashlib.h. See:

    <http://cbfalconer.home.att.net/download/>

    --
    Chuck F (cbfalconer at maineline dot net)
    Available for consulting/temporary embedded and systems.
    <http://cbfalconer.home.att.net>
    CBFalconer, Dec 8, 2006
    #2
    1. Advertising

  3. Chris Bore <> wrote:
    > If I have a self-contained server component, that specifies callback
    > functions, then would it be good practice for:


    > 1) the server component itself to provide a header file with the
    > callback function declarations
    > 2) the client to implement the function definitions


    No. Give a typedef for a pointer to callback function. For
    an example, look at how signal() is declared:

    typedef void (*sighandler_t)(int);
    extern sighandler_t signal(int signum, sighandler_t handler);

    --
    pa at panix dot com
    Pierre Asselin, Dec 8, 2006
    #3
    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. Rupert Jones
    Replies:
    6
    Views:
    774
    Kevin Goodsell
    Oct 1, 2003
  2. joshc
    Replies:
    9
    Views:
    585
  3. Kristian Virkus
    Replies:
    7
    Views:
    397
    Thad Smith
    Feb 8, 2007
  4. Belebele
    Replies:
    4
    Views:
    571
    Gavin Deane
    Oct 17, 2006
  5. vaib

    variable declaration and definition!

    vaib, Oct 5, 2007, in forum: C Programming
    Replies:
    17
    Views:
    521
Loading...

Share This Page