On Wed, 06 Feb 2013 17:36:24 -0000, Andrei Alexandrescu <[email protected]> wrote:
A good part of that is the recent debate on what &func should do (take the address of the function vs. the address of its result). With the unsafe meaning out of the way, only the safe one is eligible.

&X takes the address of X.

If X is a symbol which represents an 'int' you get the address of the int itself, not the address of the int's value.

If X is a symbol which represents a 'function' you should get the address of the function itself, not the address of that functions value (AKA the result).

That seems the most logical thing to implement, to me. I think the confusion arises because ppl conflate the symbol/variable/thing and that thing's value.

If we implement this we then have to ask how to get the address of the value. I reckon; if you want the address of the value of the function then call the function and take the address of that i.e. &func(). Here, brackets are not optional because they indicate the function is being called.

Alternately if you don't like that, perhaps &*func. So, if func is "ref int func()" then this syntax makes it analogous to an int* e.g.

int i = 5;
int *p = &i;

&p  // takes the address of the variable 'p'
&*p // takes the address of the variable 'i'

int i = 5;
ref int func() { return i; }

&func   // takes the address of func
&*func  // takes the address of i

I prefer:

&func() // takes the address of i

because to me that is clearer and nicer looking.

This seems the most logical thing to do, and seems the most flexible to me. If &func were to take the address of the value of func (result) then we'd need to invent a new syntax to take the address of func itself and why do that when we don't really need to. IMO.

R

--
Using Opera's revolutionary email client: http://www.opera.com/mail/

Reply via email to