表达能力实在有限,不知道怎么描述,先写这儿吧: c++
void (test)(int a) 函数
{ spa
printf("Test ~~: %d",a ); 指针
} ci
void test1(int a) 编译器
{ it
printf("Test ~~: %d",a ); io
} 编译
int func(int a) function
{
printf("func %d :" ,a );
return a;
}
typedef int(*fun)(int);
fun funct(int b)
{
printf("funcion :%d",b);
return func;
}
typedef fun(*funt)(int a);
typedef fun abc(int a);
---------------------------
test(10000);
test1(10000);
funt a = funct;
(a(1))(2);------------------输出:function 1func 2
abc *b = funct;
b(2);-----------------------输出:function 3
还不是很清楚c++提供 函数名加括号这种语法的意义,但广泛解释为括号调用函数是为了区别类函数宏;
另外,一个没有获得验证的解释是,extern void (test)(int a); 函数指示符加上括号后,
将发生从函数到指针的转换,并经过此指针调用函数;
不加括号的话,函数到指针的转换被抑制,直接经过函数指示符调用函数。
另外,关于int func(int a)(int b);这样的形式应该没有相应语法,只是编译器会将
typedef出的函数指针展开,造成这种形式;
eg; typedef fun(*funt)(int a);展开后为:int (*funt)(int a)(int b);
关于函数参数表后接参数表的形式不知道我确实见过仍是只是编译结果中出现过,还须要指点;
编译结果不等于语法;