Is the address-of operator (&) really needed?

Artur Skawina art.08.09 at gmail.com
Fri Jun 1 11:06:56 PDT 2012


On 06/01/12 19:41, Sandeep Datta wrote:
>>
>>    import std.stdio;
>>    @property f() { writeln("oops"); return 0; }
>>    void main() { auto p = f; }
>>
>> artur
> 
> I understand what you are trying to say but I hear parens will become mandatory soon. This may not be a problem then.

No, it's the other way around - parens are accepted now, but shouldn't be.
The whole point of properties is to behave as fields.

   import std.stdio;

   struct S {
      @property int x() { return 42; }
   }
   
   void main() { 
      S s;
      auto p1 = &s.x; writeln(p1);
      auto p2 = s.x;  writeln(p2);
   }

> While writing code we expect the compiler to understand what we want to do without writing a lot of code.

Do you really consider '&' to be "a lot of code"?

D is not as compact as it could be, but '&' is not part of that problem. It is
necessary to disambiguate and makes the code more readable by being explicit.
 
artur


More information about the Digitalmars-d mailing list