Nick Keighley wrote:
Harald van D=C4=B3k wrote:
Yevgen Muntyan wrote:
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 =E2=80=98func2=E2=80=99:
file.c:7: warning: =E2=80=98return=E2=80=99 with a value, in function=
returning void
If I recall correctly, compiler in some Microsoft Visual Studio versi=
on
told me the same thing. So, is this a compiler bug (feature), or is t=
his
"return func ();" invalid in standard C?
It's invalid in standard C. Perhaps you're thinking of C++, where it is
allowed?
since when has it been valid for a void function to return a value, in
either C or C++?
It's not legal in C++ for a "return" statement of a void function to
return a value [=C2=A76.6.3]. The above program is nonetheless OK since it
is legal in C++ for a return statement in a void function to have a
(cv) void type expression - as in this case, the return expression is
simply a call to another void function.
Greg
.