Revised RFC on range design for D2

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Mon Sep 29 13:54:27 PDT 2008


Steven Schveighoffer wrote:
> "Steven Schveighoffer" wrote
>> "Andrei Alexandrescu" wrote
>>>> Not really.  A function symbol by itself is the address of the function. 
>>>> A pointer symbol by itself is the address of the data it points to. 
>>>> It's the same.  I don't think you understood the detail that I stated, 
>>>> 'get address it's pointing to', not 'get address of the pointer'.
>>> I understood very well. Your point is off by a mile, and getting only 
>>> farther. Please understand how you are making an elementary mistake.
>>>
>>> Consider:
>>>
>>> int x;
>>>
>>> Then if I only use "x", I am getting x's value (an lvalue in fact), not 
>>> its address. Now consider:
>>>
>>> int * x;
>>>
>>> Then if I only use "x", I am getting x's value, which is the address of 
>>> an int.
>>>
>>> In neither case is it possible for x and &x to mean the same thing. For 
>>> functions some really weird stuff happens:
>>>
>>> // this is C
>>> #include <assert.h>
>>> void foo() {}
>> How does this make any difference to whether you can call a function 
>> without parentheses or not?  You are arguing that for a function defined 
>> as foo(), foo; should mean call function foo, and I'm arguing that it 
>> should be a syntax error.  Neither of us want the C behavior of evaluating 
>> to the function address.
>>
>> I think &foo should be the proper method of taking the address of a 
>> function, as it is in D.
> 
> This is what happens when you can't explain yourself correctly.  Stop typing 
> your vehement response about how I am an idiot right now :)  I realize my 
> mistake in the statements above.
> 
> I think the problem you cited with how foo is equivalent to &foo in C is 
> bad.  I think we are getting sidetracked here, though.  The point I really 
> want to state is that foo; shouldn't mean calling a function named foo.

"State" is very accurate, because aside from stating the point you bring 
nothing to support it.

> I 
> don't think it should mean the address of the function, although it seems 
> consistent with C pointers (IMO, it seems like &foo shouldn't even compile 
> in C if foo means 'address of foo' already).  &foo sounds correct to me, 
> "address of foo."

No. It does NOT seem and is NOT even remotely consistent with C pointers 
because x is not the same thing as &x for all symbols in C except 
functions. Please work through this with books and test programs and 
all, until you fully understand it. It is important.

> Bottom line, I'm not defending the way C takes addresses of functions, but I 
> think the requirement C has to use parentheses to call functions helps to 
> clarify the intentions of the function author, and makes the code clearer.

I agree, and I'd agree even more if you replaced "think" with "believe". 
I hope you also agree you have brought nothing of significance to 
support your thought/belief, while you have received plenty against.

I also agree that Sergey, Bill, and others did bring up good points in 
support for the required trailing "()". It would be more fertile to 
continue discussing those.


Andrei


More information about the Digitalmars-d-announce mailing list