Consider the following code snippet :The wording is not ideal, but it is not nonsense!
/*================================*/
/* void.c */
void f(int i)
{
i++;
if (i!=10)
return f(i);
}
int main(void)
{
f(0);
return 0;
}
/*================================*/
gcc warns me with the following message:
void.c: In function "f":
void.c:5: attention : "return" with a value, in function returning void
"return with a value" ? what a nonsense !
The function f returning no value (void), the instructionNo. A diagnostic is required since the program violates a
return f();
isn't an error. It's equivalent to a return statement, apart from the
function call.
This is a compiler's bug, isn't it ?
constraint:
6.8.6.4 The return statement
Constraints
1 A return statement with an expression shall not appear in a function
whose return type is void. A return statement without an expression
shall only appear in a function whose return type is void.
A better message might have been "return with an expression in a
function whose return type is void", but it is the construct that is
wrong, not the compiler.
The "obvious" way to write what you want is just:
void f(int i)
{
i++;
if (i != 10)
f(i);
}
--
Ben.