
Am Wednesday 25 November 2009 21:54:54 schrieb Jeffrey Bosboom:
Stefan Strasser wrote:
this is just an idea off the top of my head, I haven't thought this through, but has the committee ever considered making functions overloadable by their return type?
void f(); // 1 int f(); // 2
int main(){ f(); //resolves to 1 int b=f(); //resolves to 2 }
That's a pretty drastic language change to solve an issue that is really a library problem.
I don't want to argue for it because as I've said, I haven't really thought this through. but this isn't a library specific problem, it applies to unnecessary evaluation of discarded return values in general. it's just exacerbated in this case because you can't just add a parameter or create a second function like you normally would because the function signature is specified.
(Besides, what if I want to call function 2 for its side effects and ignore its return type? Even the ugly "(void)f()" doesn't seem to do what I want.)
I can't think of a reason why you'd want that, but (int) f(); should do the trick.