S
Sathyaish
I am practicing function pointers. Here's what I am doing: passing a
function pointer to another function. It all goes well except for the
two warnings I get:
(1) 'ConsumeFnPointer' : too many actual parameters
(2) declared formal parameter list different from definition
I am curious as to why I get those warnings. Can we not pass variable
arguments to the right of the function pointer argument? Has it got
something to do with the calling sequence (__stdcall, ___pascal etc.)?
Here's the code:
#include <stdio.h>
/*float Add(float, float);
float Subtract(float, float);
float Multiply(float, float);
float Divide(float, float);
float (*ptr)(float, float);
*/
int DoSomething(int, int);
int ConsumeFnPointer(int (*ptr1)(int, int));
int main()
{
//ptr=&Add;
//printf("%f",ptr(3,9));
printf("%d", ConsumeFnPointer(&DoSomething,12,4));
}
/*float Add(float a, float b) { return a+b;}
float Subtract(float a, float b){ return a-b;}
float Multiply(float a, float b){ return a*b;}
float Divide(float a, float b){ return a/b;}
*/
int ConsumeFnPointer(int (*ptr1)(int a, int b), int a, int b)
{
return (*ptr1)(a,b);
}
int DoSomething(int a, int b)
{
return 1+a-b;
}
function pointer to another function. It all goes well except for the
two warnings I get:
(1) 'ConsumeFnPointer' : too many actual parameters
(2) declared formal parameter list different from definition
I am curious as to why I get those warnings. Can we not pass variable
arguments to the right of the function pointer argument? Has it got
something to do with the calling sequence (__stdcall, ___pascal etc.)?
Here's the code:
#include <stdio.h>
/*float Add(float, float);
float Subtract(float, float);
float Multiply(float, float);
float Divide(float, float);
float (*ptr)(float, float);
*/
int DoSomething(int, int);
int ConsumeFnPointer(int (*ptr1)(int, int));
int main()
{
//ptr=&Add;
//printf("%f",ptr(3,9));
printf("%d", ConsumeFnPointer(&DoSomething,12,4));
}
/*float Add(float a, float b) { return a+b;}
float Subtract(float a, float b){ return a-b;}
float Multiply(float a, float b){ return a*b;}
float Divide(float a, float b){ return a/b;}
*/
int ConsumeFnPointer(int (*ptr1)(int a, int b), int a, int b)
{
return (*ptr1)(a,b);
}
int DoSomething(int a, int b)
{
return 1+a-b;
}