不带参数类型的函数指针? [英] Function pointer without arguments types?

查看:402
本文介绍了不带参数类型的函数指针?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

这篇关于不带参数类型的函数指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆