Revised RFC on range design for D2

Steven Schveighoffer schveiguy at yahoo.com
Mon Sep 29 13:02:43 PDT 2008


"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.  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."

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.

-Steve 




More information about the Digitalmars-d-announce mailing list