
typedef的用法是在定义前加上这个关键字就能得到一个新的类型名例如int a;变成typedef int a ;那么就可以用a表示Int了。比如void (*test)(void);那么加上typedef就变成了typedef void (*test)(void);类型名test就表示一个返回值是void参数是void的一个函数指针类型与上面的int a不同这里的变量名是testvoid test_opr(void) {}; typedef void (*test)(void); test ptr test_opr; ptr();void test(void);这个函数声明表示定义了一个参数为void返回空的test函数。并且这里面的test的值就是存储函数指针也就是这个函数的第一条语句的内存地址。*为解引用操作对函数进行解引用操作*test按道理讲要返回函数内容也就是函数体但是事实上没法返回函数体。就对解引用降级退化所以test和*test以及**test不管多少个解引用结果都是这个函数的内存地址。但还是注意test和*test本质上是不一样的一个是函数指针存储函数的第一条汇编指令的内存地址一个是这个函数的函数体在输出的时候会隐式退化成test。#include stdio.h static int count 0; void test(void) { printf(test count %d task start\n, count); } void (*test_por)(void) test; int main() { printf(test value 0x%X, *test value 0x%X **test value 0x%X test value 0x%X\n, test, *test, **test, test); test(); (*test)(); (**test)(); (*test_por)(); (test)(); //(test_por)(); //注意此时这个test_por是存储函数内存地址的容器也就是说test_por获取到的是存储函数内存地址的地址所以可以看到后面输出的test_por地址和test_por不同。也就是说test_por存储的内存数据test_por是存储这个数据的内存地址 //事实上test_por存储的是函数体的第一条指令的地址 printf(test_por value 0x%X, *test_por value 0x%X **test_por value 0x%X test_por value 0x%X\n, test_por, *test_por, **test_por, test_por); while(1) { } return 0; }输出的结果也能证实test value 0x681F14A4, *test value 0x681F14A4 **test value 0x681F14A4 test value 0x681F14A4 test count 0 task start test count 1 task start test count 2 task start test count 3 task start test count 4 task start test_por value 0x681F14A4, *test_por value 0x681F14A4 **test_por value 0x681F14A4 test_por value 0x681F9000