ref is pointer sugar?

Jacob Carlborg doob at me.com
Fri Aug 6 08:41:17 PDT 2010


On 2010-08-06 15:33, Pluto wrote:
> == Quote from Steven Schveighoffer (schveiguy at yahoo.com)'s article
>> On Fri, 06 Aug 2010 08:51:31 -0400, Pluto<pluto at planets.not>  wrote:
>>> Are these equivalent?
>>>
>>> S s;//struct
>>>
>>> void f(ref S s){s.x++;}
>>> f(s);
>>>
>>> void f2(S* s){(*s).x++;}
>>> f2(&s);
>> They are pretty much equivalent.  I think the code generated actually will
>> be exactly the same.  However, the compiler treats ref differently than
>> pointers.  For example, ref is allowed in the safe subset of D, and
>> pointers are not.
>> Note that you do not need to dereference pointers to access their
>> pointed-to members.  i.e.:
>> void f2(S* s){s.x++;}
>
> Where is this in the spec? I can't find it. Still used to ->

http://www.digitalmars.com/d/1.0/class.html section "Fields".

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list