Function pointers, variable argument functions calling other variable-argument functions (sort of)

Discussion in 'C Programming' started by S?ren Gammelmark, Jan 7, 2005.

  1. Hi

    I have been searching the web and comp.lang.c of a method of using
    variable-argument function pointers and the like. And some of the
    questions arising in this post are answered partly in these posts, but
    I ask mainly for a way to found a way to solve this problem. I'm a
    hobbyist so there might be an alltogether better solution to the
    problem, so please come with any solution you might think of. I'm open
    to ideas. --- And i'm not bound by C. Suggestions from C++ are
    welcome.

    I need an extensible multithreaded application (i'm thinking windows
    here since I have no experience on other systems, but I think the
    problem is quite similar on other os). I would like to make the
    extensibility as natural for the user-programmer as possible without
    that programmer needing to think (very much) about multithreading. For
    this reason I would like the user-programmer to be able to define a
    function like this:


    int Filter1(DataSegment segment, float a, float b, int value);
    int Filter2(DataSegment segment, float start, float end);

    then in the program itself, it should be possible to make a call
    something like this


    InvokeFilter(&Filter1, 0.5f, 43.0f, 120);

    or

    InvokeFilter(&Filter2, 0.2f, 1.2f);


    InvokeFilter should then be able to spawn the necessary threads and
    call Filter1 with the arguments 0.5f, 43.0f, 120 (and an appropriate
    DataSegment, which tells the filter where to operate). My first
    thought of solving this problem was to define a function-pointer of
    the form


    typedef int (*PROC_MULTITHREAD)(DataSegment segment, ...);


    and then define InvokeFilter as

    int InvokeFilter(PROC_MULTITHREAD filter, ...)

    where InvokeFilter will call the function pointed to by filter, and
    pass the extra (...) arguments. But as I have read around the net,
    this is not supported by C (which I find a bit odd, since I can't see
    the essential difference.). It is not possible for me to define som
    general model which all filter-functions will conform to. The obvious
    solution is ofcourse to implement a list containing the arguments, but
    I think it would be somewhat annoying for the programmer of the
    filter-functions to use some object for retrieving arguments.

    Comments? Suggestions?

    Søren Gammelmark
     
    S?ren Gammelmark, Jan 7, 2005
    #1
    1. Advertising

  2. S?ren Gammelmark

    Eric Sosman Guest

    Re: Function pointers, variable argument functions calling othervariable-argument functions (sort of)

    Søren Gammelmark wrote:
    >
    > I have been searching the web and comp.lang.c of a method of using
    > variable-argument function pointers and the like. [...]
    > [Synopsis: Call a variadic "wrapper" function that in turn
    > calls the "wrapped" function, passing the variable arguments.]


    At least part of what you're asking is addressed by
    Question 15.12 in the comp.lang.c Frequently Asked Questions
    (FAQ) list

    http://www.eskimo.com/~scs/C-faq/top.html

    That's about the best you can do with C. If you want Lisp,
    you know where to find it ;-)

    --
     
    Eric Sosman, Jan 7, 2005
    #2
    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. Ben Kial
    Replies:
    1
    Views:
    663
    Eric Enright
    Nov 15, 2004
  2. D3|\\||\\|!$
    Replies:
    3
    Views:
    3,503
    Ian Collins
    Feb 25, 2008
  3. D3|\\||\\|!$
    Replies:
    20
    Views:
    939
    Gerry Ford
    Feb 29, 2008
  4. Navin
    Replies:
    1
    Views:
    705
    Ken Schaefer
    Sep 9, 2003
  5. AikidoGuy
    Replies:
    11
    Views:
    560
    Seebs
    Nov 21, 2011
Loading...

Share This Page