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?
I’m not convinced that any of the reasons I’ve heard are good ones.
See, in C++, you can return a
voidfunction’s result:Yes, it’s exactly the same as:
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
voidreturn.So, if a similar system applied so that a
voidreturn constituted a nullary call in a function composition scenario, that could make function composition more generic too.