Anyway to achieve the following

JG JG at somewhere.com
Fri Aug 13 08:25:33 UTC 2021


Suppose one has a pointer p of type T*.
Can on declare variable a of type T which is stored in the 
location pointed to by p?

As an example if we have:

     struct S
     {
       int x = 1234;
     }

     void main() {
        S s;
        //unknown construction of a using &(s.x)
        writeln(a); //displays 1234
        s.x = s.x+1;
        writeln(a); //displays 1235
        a = a +1;
        writeln(s.x); //displays 1236
     }
----------------------------------------------------------------
Similar behavior can be achieved in the body of the lambda here

     import std.stdio;

     struct S
     {
       int x = 1234;
     }


     void main() {
         S s;
         (ref a){
              writeln(a);
              s.x = s.x + 1;
              writeln(a);
              a = a +1;
              writeln(s.x);
         }(s.x);
     }




More information about the Digitalmars-d-learn mailing list