On Fri, 06 Aug 2010 08:51:31 -0400, Pluto <pl...@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++;}


If so, why is it stated that ref is very rarely used?
It looks like something I would use a lot with structures.

What? Where does it say that? That's very wrong, ref is used everywhere. If not explicitly, at least every struct member function passes 'this' by ref.

-Steve

Reply via email to