Monday, 26 August 2013

A typedef function as a parameter of another function

A typedef function as a parameter of another function

typedef int (xxx)(int yyy); means define a function which named xxx with
an integer parameter. you can see this SO post for details.
I have tried this in different ways, that is my code:
#include<stdio.h>
#include<stdlib.h>
typedef int (xxx)(int yyy);
void f1(xxx a)
{
printf("f1:%d\n",a);
}
void f2(xxx *a)
{
printf("f2:%d\n",a);
}
int test(int y)
{
}
int main()
{
xxx *a;
f1(test);
f1(a);
f2(test);
f2(a);
xxx b;
printf("xxx's size:%d\n", sizeof(b));
}
output:
f1:4199274
f1:2
f2:4199274
f2:2
xxx's size:1
My question:
f(xxx a) is the same as f(xxx *a)?
sizeof(someFunction) is defined or not?

No comments:

Post a Comment