Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   Function as parameter of a function with parameters (http://www.velocityreviews.com/forums/t690374-function-as-parameter-of-a-function-with-parameters.html)

marc 07-07-2009 12:53 PM

Function as parameter of a function with parameters
 
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.

James Kuyper 07-07-2009 01:18 PM

Re: Function as parameter of a function with parameters
 
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);
// ...
}

marc 07-07-2009 01:39 PM

Re: Function as parameter of a function with parameters
 
On 7 juil, 15:18, James Kuyper <jameskuy...@verizon.net> 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 07-07-2009 02:28 PM

Re: Function as parameter of a function with parameters
 
On 7 juil, 15:57, Simon Connah <simon.con...@googlemail.com> wrote:

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


Thanks, the tip was indeed to pass the parameters distinctly.


All times are GMT. The time now is 10:22 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.