typedef int (xxx)(int yyy);
似乎定义了一个名为 xxx
的函数指针,它指向一个带有整数参数的函数 yyy
.
但是我不明白那个语法...任何人都可以给出一个很好的解释吗?
我发现 typedef int xxx(int yyy);
仍然有效。它们有什么区别吗?
最佳答案
这定义了函数类型,而不是函数指针类型。
typedef
的模式是它修改任何声明,而不是声明一个对象,它声明一个对象将具有的类型的别名。
这是完全有效的:
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
名称作为函数定义中的整个类型。
关于c - 如何理解 "typedef int (xxx)(int yyy);"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18456275/