void func()返回值?

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)
{

}


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?