On 2011-09-22 23:46, Walter Bright wrote:
On 9/22/2011 1:13 PM, Jacob Carlborg wrote:
I function/delegate that returns a value should be implicitly
converted to a
function/delegate that returns void.
That doesn't work in some cases - consider a function that returns an
object that the caller must destruct. Or even just returns a struct -
the caller passes in a hidden pointer to where the return type gets
written.
What I'm saying is that you can ignore the returned value of a delegate
therefore I think it should be possible implicitly convert a delegate
returning a value, to a delegate returning void. The same for function
pointers as well. Example:
void main ()
{
int delegate () bar = { return 1; };
void delegate () foo = bar;
int a = bar(); // here we call "bar" and handles the return value
bar(); // here we call "bar" and ignores the return value
foo(); // here we call "foo", same as the line above
}
Or are you saying that it would be strange and confusing when calling a
delegate that returns void, a struct could be destructed on the callers
side? I can agree with that.
Implicit conversion of function pointers and delegates requires binary
ABI compatibility.
I'm not suggesting that a function pointer should be implicitly
converted to a delegate, if that what is what you are saying.
--
/Jacob Carlborg