It is valid to return a void-function, or cast a variable to void, from a void-function. This makes some sense, in particular in C++ since we might have a template, and we would like to put 'void' as type in this C++ template. But then maybe it should also be allowed to put 'void' as inparameter to a void-function, but then compiler warns about too many arguments. void.c: In function ‘main’: void.c:16: error: too many arguments to function ‘f1’ void.c:17: error: too many arguments to function ‘f2’ Somehow it would be more 'aligned' to have function-return-values and function-in-parameters work the same way, so that template-alike-constructions, or similar pure C macro/preprocessor constructions, could work the same perhaps? void f1(void) { return (void)0; //OK } void f2(void) { return f1(); //OK } int main(void) { f1(); //OK f2(); //OK f1((void)0); //ERROR f2(f1()); //ERROR return 0; }
void f1(void) declares a function that takes no parameters.
Ok, but also f1() declares that it does not return any parameters, still it can return (void)0; I'm not saying either is wrong, I just though it should be consistent. If its ok to _return_ (void) from a function, why is it not ok to have (void) as _inparameter_ to a function. Where is the logical difference? /Fredrik
(In reply to comment #0) > > void f1(void) > { > return (void)0; //OK This is valid in C++ but allowing it in C is a GCC extension. > void f2(void) > { > return f1(); //OK This is valid in C++ but allowing it in C is a GCC extension. > f1((void)0); //ERROR > f2(f1()); //ERROR This is repulsive. I don't see this as "more aligned" with the examples above, I see it as more aligned with: int i = (int) f1(); // EURGH Or consider the following, how many arguments are given to f3? void f3(int); f3((void)0, f1(), f2(), 3); // EURGH
Yes, I agree its EURGH. I guess its not preferred to make C++ template-alike code in C. I think its worth avoid stuff like: #ifdef BLAH_BLAH_BLAH #define RETURN_TYPE_C_TEMPLATE void #define PARAM_TYPE_C_TEMPLATE void #define PARAM_TYPE_C_TEMPLATE_VARIABLE #else #define RETURN_TYPE_C_TEMPLATE int #define PARAM_TYPE_C_TEMPLATE int #define PARAM_TYPE_C_TEMPLATE_VARIABLE var #endif RETURN_TYPE_C_TEMPLATE func( PARAM_TYPE_C_TEMPLATE PARAM_TYPE_C_TEMPLATE_VARIABLE ) { return (RETURN_TYPE_C_TEMPLATE) template_func1( PARAM_TYPE_C_TEMPLATE_VARIABLE ); } int main(void) { func((PARAM_TYPE_C_TEMPLATE) template_func2()); return ERR_EURGH; }
If you want the standard to be changed then this is the wrong place.