C/C++: Calling function with no arguments with function which returns nothing

c, c++

Solution

I'm not convinced that any of the reasons I've heard are good ones.

See, in C++, you can return a `void` function's result:

void foo() {
    // ...
}

void bar() {
    // ...
    return foo();
}

Yes, it's exactly the same as:

foo();
return;

but is much more consistent with generic programming, so that you can make a forwarding function work without having to worry about whether the function being forwarded has `void` return.

So, if a similar system applied so that a `void` return constituted a nullary call in a function composition scenario, that could make function composition more generic too.

Problem

Why isn't it possible to call a function which takes no arguments with a function call as argument which does not return any value (which IMHO is equivalent to calling a function which takes no arguments with no arguments). For example: ``` void foo(void) {...} void bar(void) {...} foo(bar()) ``` Don't get me wrong, I know `void` is not a value and that it cannot be treated like one. With my logic it would make sense and it should be possible to do that. I mean, why not? Any argument why that should not be possible?

Original source