Function as parameter of a function with parameters

Discussion in 'C Programming' started by marc, Jul 7, 2009.

  1. marc

    marc Guest

    Hello,

    I can do :

    void DoFunct(void (*funcp)());

    void MyFunct()
    {
    //...
    }

    DoFunct(MyFunct);

    but is it possible to pass to DoFunct() a function MyFunct with
    parameters ?

    Thanks in advance.
     
    marc, Jul 7, 2009
    #1
    1. Advertising

  2. marc

    James Kuyper Guest

    marc wrote:
    > Hello,
    >
    > I can do :
    >
    > void DoFunct(void (*funcp)());
    >
    > void MyFunct()
    > {
    > //...
    > }
    >
    > DoFunct(MyFunct);
    >
    > but is it possible to pass to DoFunct() a function MyFunct with
    > parameters ?
    >
    > Thanks in advance.


    void DoFunct(void(*funcp)(int));

    void MyFunct(int i)
    {
    // ...
    }

    int main(void)
    {
    DoFunct(MyFunct);
    // ...
    }
     
    James Kuyper, Jul 7, 2009
    #2
    1. Advertising

  3. marc

    marc Guest

    On 7 juil, 15:18, James Kuyper <> wrote:

    > int main(void)
    > {
    >         DoFunct(MyFunct);


    Thanks for your answer, but my problem is how can I pass and read the
    parameters of MyFunct ?

    DoFunct(MyFunct(1)); => doesn't compile.

    And inside DoFunct, I'm not able to read the parameters :
    This doesn't compile=>

    void DoFunct(void(*funcp)(int i))
    {
    (*funcp)(i);
    }
     
    marc, Jul 7, 2009
    #3
  4. marc

    marc Guest

    On 7 juil, 15:57, Simon Connah <> wrote:

    > void DoFunct(int i, void (*funcp)(int))


    Thanks, the tip was indeed to pass the parameters distinctly.
     
    marc, Jul 7, 2009
    #4
    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. Boris Sargos
    Replies:
    3
    Views:
    423
    Boris Sargos
    Apr 23, 2004
  2. Jason
    Replies:
    2
    Views:
    542
    Jonathan Mcdougall
    May 13, 2006
  3. mosscliffe
    Replies:
    6
    Views:
    321
  4. Florian Loitsch
    Replies:
    11
    Views:
    259
    Michael Winter
    Mar 15, 2005
  5. AzamSharp
    Replies:
    2
    Views:
    192
Loading...

Share This Page