我试图声明一个函数指针,指向任何返回相同类型的函数。我省略了指针声明中的参数类型以查看将生成什么错误。但是程序编译成功,执行没有任何问题。
这是正确的声明吗?我们不应该指定参数类型吗?
#include <stdio.h>
#include <stdlib.h>
void add(int a, int b)
{
printf("a + b = %d", a + b);
}
void (*pointer)() = &add;
int main()
{
add(5, 5);
return 0;
}
输出:
a + b = 10
最佳答案
类型名称中的空括号表示未指定的参数。请注意,这是一个过时的功能。
C11(ISO/IEC 9899:201x) §6.11.6 Function declarators
The use of function declarators with empty parentheses (not prototype-format parameter type declarators) is an obsolescent feature.
关于c - 没有参数类型的函数指针?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20835534/