Proposal: Reference Variables

Hasan Aljudy hasan.aljudy at gmail.com
Mon Apr 10 17:37:46 PDT 2006


Bruno Medeiros wrote:
> Hasan Aljudy wrote:
> 
>> S. Chancellor wrote:
>>
>>> I would like to suggest the following variable type added to D as a 
>>> supplement to pointers.  Please review the following code and suggest 
>>> modifications and additions as you see.
>>>
>>> Thanks!
>>>
>>> -S.
>>>
>>> Oh yes, and please assume all the following asserts PASS.
>>>
>>>
>>> long x = 2;
>>> long& y = &x;
>>>
>>> assert(y == 2);
>>>
>>> y = 4;
>>>
>>> assert(x == 4);
>>>
>>> assert(&y == &x);  //Notice the change in the operation of &.  Not a 
>>> handle to x!
>>>
>>> long z = 5;
>>>
>>> &y = &z;  //& Allows l-value assignment,
>>>
>>> assert( y == 5 );
>>>
>>> assert( &y == &z );
>>>
>>> assert(y.sizeof == z.sizeof);  //Sizeof gives information on 
>>> referenced type, not reference.  Ditto for other properties
>>>
>>
>> While I like the idea of references and refernce semantics for things 
>> like structs and whatnot, I think the C++ & operator is the *wrong* 
>> way to do it.
> 
> 
> What do you mean "reference semantics"? "References" (as in "reference 
> variables, "alias references", or "c++ references") do not give 
> "reference semantics", (as in "reference types").
> 

Maybe I don't understand the meaning of "semantics"!
What I mean by "Reference semantics" is reference behavior applied to 
pointers. (if that makes it any clearer ..)



More information about the Digitalmars-d mailing list