void func()返回值? [英] void func () returning value?

查看:159
本文介绍了void func()返回值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,


请考虑以下代码:


void func(void)

{

}


void func2(无效)

{

return func();

}


gcc -pedantic说如下:


muntyan @ munt10:/ tmp $ gcc -pedantic -c file。 c

file.c:在函数中?func2?:

file.c:7:警告:?返回?有一个值,在函数中返回void


如果我没记错的话,一些Microsoft Visual Studio版本中的编译器

告诉了我同样的事情。那么,这是一个编译器错误(功能),还是这个

" return func();"标准C无效?


谢谢,

Yevgen

Hey,

Consider the following code:

void func (void)
{
}

void func2 (void)
{
return func ();
}

gcc -pedantic says the following:

muntyan@munt10:/tmp$ gcc -pedantic -c file.c
file.c: In function ?func2?:
file.c:7: warning: ?return? with a value, in function returning void

If I recall correctly, compiler in some Microsoft Visual Studio version
told me the same thing. So, is this a compiler bug (feature), or is this
"return func ();" invalid in standard C?

Thanks,
Yevgen

推荐答案

gcc -pedantic -c file.c

file.c:在函数中?func2?:

file.c:7:警告:?返回?有一个值,在函数中返回void


如果我没记错的话,一些Microsoft Visual Studio版本中的编译器

告诉了我同样的事情。那么,这是一个编译器错误(功能),还是这个

" return func();"标准C无效?


谢谢,

Yevgen
gcc -pedantic -c file.c
file.c: In function ?func2?:
file.c:7: warning: ?return? with a value, in function returning void

If I recall correctly, compiler in some Microsoft Visual Studio version
told me the same thing. So, is this a compiler bug (feature), or is this
"return func ();" invalid in standard C?

Thanks,
Yevgen


Yevgen Muntyan写道:
Yevgen Muntyan wrote:

嘿,


请考虑以下代码:


void func(void)< br $>
{

}


void func2(无效)

{

return func();

}


gcc -pedantic说如下:


muntyan @ munt10: / tmp
Hey,

Consider the following code:

void func (void)
{
}

void func2 (void)
{
return func ();
}

gcc -pedantic says the following:

muntyan@munt10:/tmp


gcc -pedantic -c file.c

file.c:在函数中?? ?? func2a ??:

file.c:7:警告:a ?? returna ??有一个值,在函数中返回void


如果我没记错的话,一些Microsoft Visual Studio版本中的编译器

告诉了我同样的事情。那么,这是一个编译器错误(功能),还是这个

" return func();"标准C无效?
gcc -pedantic -c file.c
file.c: In function a??func2a??:
file.c:7: warning: a??returna?? with a value, in function returning void

If I recall correctly, compiler in some Microsoft Visual Studio version
told me the same thing. So, is this a compiler bug (feature), or is this
"return func ();" invalid in standard C?



它在标准C中是无效的。也许你在想C ++,它允许在哪个


It''s invalid in standard C. Perhaps you''re thinking of C++, where it is
allowed?


这篇关于void func()返回值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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