不带参数类型的函数指针?

编程入门 行业动态 更新时间:2024-10-28 12:16:08
本文介绍了不带参数类型的函数指针?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图定义一个函数指针指向返回相同类型的任何功能。我省略了指针​​声明的参数类型,看看会产生什么样的错误。但该方案已成功编译和执行没有任何问题。

这是一个正确的声明?我们不应该指定的参数类型?

的#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 declarators

The use of function declarators with empty parentheses (not prototype-format parameter type declarators) is an obsolescent feature.

更多推荐

不带参数类型的函数指针?

本文发布于:2023-10-26 12:38:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1530169.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不带   指针   函数   参数   类型

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!