C函数指针与类型定义

#include
#define PI 3.14

typedef int uint32_t;
/*
pfun is a pointer
and its type is void (*)(void)
*/
void (*pfun)(void);

/*
afer typedef like this
we can use “pfun1” as a data type to a function
that has form like:
/ ------------------------------- /
- function has no return value
- function has no paramter
void function name;
/ ------------------------------- /
you can find an example in main fucntion.
*/
typedef void (*pfun_typedef)(void);
void PrintHello(void);

int main()
{

uint32_t i = 1;
pfun = PrintHello;
pfun_typedef p = PrintHello;

printf("%d\n", i);
printf("%f\n", PI);
pfun();
/*
	p is function pointer that has a data 	
	type p, which has been typedef like this:
		/ ------------------------------- /
		typedef void (*pfun_typedef)(void);
		/ ------------------------------- /
	so we have a shorten form of function pointer
*/
p();

return 0;

}

void PrintHello(void)
{
printf(“Hello World\n”);
}

你可能感兴趣的:(C,c语言,算法,linux)