如何理解"的typedef INT(XXX)(INT YYY);"? [英] How to understand "typedef int (xxx)(int yyy);"?
问题描述
的typedef INT(XXX)(INT YYY);
似乎定义一个名为函数指针 XXX
指向一个整数参数的函数 YYY
。
typedef int (xxx)(int yyy);
seems to define a function pointer named xxx
which points to a function with a integer parameter yyy
.
但我无法理解,语法...难道任何人给一个很好的解释?
But I can't understand that syntax...Could any one give a good explanation?
我觉得的typedef INT XXX(INT YYY);
仍然有效。它们之间有什么区别?
I find typedef int xxx(int yyy);
still works. Any difference between them?
推荐答案
这定义一个函数类型,而不是一个函数指针类型。
This defines a function type, not a function pointer type.
与的typedef
的模式是,它改变这样的声明,而不是声明一个对象,它声明的别名对象有类型。
The pattern with typedef
is that it modifies any declaration such that instead of declaring an object, it declares an alias to the type the object would have.
这是完全合法的:
typedef int (xxx)(int yyy); // Note, yyy is just an unused identifier.
// The parens around xxx are also optional and unused.
xxx func; // Declare a function
int func( int arg ) { // Define the function
return arg;
}
C和C ++语言具体而言,大发慈悲,不允许使用的typedef
的名字作为一个函数定义整个类型。
The C and C++ languages specifically, and mercifully, disallow use of a typedef
name as the entire type in a function definition.
这篇关于如何理解"的typedef INT(XXX)(INT YYY);"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!