我试图定义一个函数指针指向返回相同类型的任何功能。我省略了指针声明的参数类型,看看会产生什么样的错误。但该方案已成功编译和执行没有任何问题。
这是一个正确的声明?我们不应该指定的参数类型?
的#include<&stdio.h中GT;#包括LT&;&stdlib.h中GT;无效添加(INT A,INT B){ 输出(A + B =%d个,A + B);}无效(*指针)()=&安培;增加;诠释的main(){ 添加(5,5); 返回0;}输出:
A + B = 10解决方案
空括号中的一个类型名字的意思是不确定的参数。请注意,这是一个过时的功能。
C11(ISO / IEC 9899:201X)§6.11.6函数声明使用的函数声明与空括号(没有原型的格式参数 类型的声明)是一个过时的功能。
I was trying to declare a function pointer that points to any function that returns the same type. I omitted the arguments types in the pointer declaration to see what error will be generated. But the program was compiled successfully and executed without any issue.
Is this a correct declaration? Shouldn't we specify the arguments types?
#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; }Output:
a + b = 10解决方案
Empty parentheses within a type name means unspecified arguments. Note that this is an obsolescent feature.
C11(ISO/IEC 9899:201x) §6.11.6 Function declaratorsThe use of function declarators with empty parentheses (not prototype-format parameter type declarators) is an obsolescent feature.
更多推荐
不带参数类型的函数指针?
发布评论