忘记在返回值的函数中写入返回值 [英] Forgetting to write a return in a function returning a value

查看:146
本文介绍了忘记在返回值的函数中写入返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我的编译器(g ++)没有这样的标记为错误:


int main()

{

}



Why doesn''t my compiler (g++) flag something like this as an error:

int main()
{
}

?

推荐答案

他******* @ gmail.com 写道:
he*******@gmail.com writes:

>为什么没有''我的编译器(g ++)标记这样的错误:
>Why doesn''t my compiler (g++) flag something like this as an error:


> int main()
{
}
>int main()
{
}



因为主要'特别。在另一个函数中尝试相同的事情。

Because main''s special. Try the same thing in another function.


他* ******@gmail.com 写道:

为什么我的编译器(g ++)不会将此类标记为错误:


int main()

{

}



Why doesn''t my compiler (g++) flag something like this as an error:

int main()
{
}

?



因为它不是错误,实际上是绝对正确的。在C ++中,

void参数对任何函数都是隐含的。对于main,如果你没有写明确的回报,则返回0是隐含的
。另外主要是唯一的

两种正确的写作方式是:


int main()

{

}





int main(int argc,char * argv [])

{

}


int main(无效)错误。


-

George Kettleborough

Because it''s not an error, in fact is is absolutely correct. In C++ the
void argument is implicit for any function. For main, return 0 is
implicit if you don''t write an explicit return. Also for main the only
two proper ways to write it are:

int main()
{
}

and

int main(int argc, char* argv[])
{
}

int main(void) is wrong.

--
George Kettleborough


G Kettleborough写道:
G Kettleborough wrote:
他******* @ gmail.com 写道:

>为什么不是我的编译器( g ++)将这样的东西标记为错误:

int main()
{
}


>Why doesn''t my compiler (g++) flag something like this as an error:

int main()
{
}

?



因为它不是错误,实际上是绝对正确的。在C ++

中,void参数对于任何函数都是隐式的。对于main,如果你没有写明确的回报,则返回0是隐含的
。另外主要是唯一的

两种正确的写作方式是:


int main()

{

}





int main(int argc,char * argv [])

{

}


int main(void)错误。


Because it''s not an error, in fact is is absolutely correct. In C++
the void argument is implicit for any function. For main, return 0 is
implicit if you don''t write an explicit return. Also for main the only
two proper ways to write it are:

int main()
{
}

and

int main(int argc, char* argv[])
{
}

int main(void) is wrong.



不,不是。这很难看,但没错。


V

-

请删除资金''通过电子邮件回复时的答案

我没有回复最热门的回复,请不要问

No, it isn''t. It''s ugly, but it''s not wrong.

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask


这篇关于忘记在返回值的函数中写入返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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