这种功能的目的是什么? [英] What is the purpose of such a function ?

查看:69
本文介绍了这种功能的目的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!


这样一个函数的目的是什么?

int函数(无效)

{


返回1;

}


它似乎完全等同于

int功能()

{


返回1;

}


是它的C与C ++编译器的行为不同吗?


问候,

Razvan

Hi!

What is the purpose of such a function ?
int function(void)
{

return 1;
}

It seems to be completely equivalent with
int function()
{

return 1;
}

Is its behaviour different on a C versus a C++ compiler ?

Regards,
Razvan

推荐答案

在< 15 ************************** @ posting.google.com> mi*****@mailcity.com (Razvan)写道:
In <15**************************@posting.google.com > mi*****@mailcity.com (Razvan) writes:
这个功能的目的是什么?

int功能(无效)
{
返回1;
}

似乎完全等同于

int function()
{
返回1;
}

它的行为是否与C相比有所不同C ++编译器?
What is the purpose of such a function ?

int function(void)
{
return 1;
}

It seems to be completely equivalent with

int function()
{
return 1;
}

Is its behaviour different on a C versus a C++ compiler ?




是的。在C编译器上,后者是旧式函数定义,

没有为函数提供原型:


fangorn:〜/ tmp 183> cat test.c

int function(){return 0; }


int main(){return function(2,3); }

fangorn:〜/ tmp 184> gcc test.c

fangorn:〜/ tmp 185> g ++ test.c

test.c:在函数`int main()''中:

test.c:1:错误:函数`int函数的参数太多()''

test.c:3:错误:此时在文件中


原始版本在C和C ++下具有相同的语义。 br />

Dan

-

Dan Pop

DESY Zeuthen,RZ集团

电子邮件: Da*****@ifh.de


mi*****@mailcity.com (Razvan)在留言中写道:< 15 *** ***********************@posting.google。 com> ...
mi*****@mailcity.com (Razvan) wrote in message news:<15**************************@posting.google. com>...
这样一个函数的目的是什么?

int函数(void)


/>返回1;
}
这似乎完全等同于

int function()


返回1;
}

它在C与C ++编译器上的行为是不同的?
What is the purpose of such a function ?

int function(void)
{

return 1;
}

It seems to be completely equivalent with

int function()
{

return 1;
}

Is its behaviour different on a C versus a C++ compiler ?




我是这么认为的。 />

在C中:int f(void); delcares一个没有参数的函数

返回一个int。 " int f();"声明一个函数没有

参数SPECIFICATION返回一个int。



I think so.

In C: "int f(void);" delcares a function with NO parameters
returning an int. "int f();" declares a function with no
parameter SPECIFICATION returning an int.


在< a5 ************ **************@posting.google.com> k_*****@yahoo.com (kal)写道:
In <a5**************************@posting.google.com > k_*****@yahoo.com (kal) writes:
在C中:int f(void); delcares一个没有参数的函数
返回一个int。 " int f();"声明一个函数没有
参数SPECIFICATION返回一个int。
In C: "int f(void);" delcares a function with NO parameters
returning an int. "int f();" declares a function with no
parameter SPECIFICATION returning an int.




嗯,它仍然指定一些东西:未知数量的参数
$ b未知类型的$ b是固定的,即f()不能是一个可变函数。


Dan

-

Dan流行

DESY Zeuthen,RZ集团

电子邮件: Da ***** @ ifh.de


这篇关于这种功能的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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