Get the address of an object, within the object itself

Jacob Carlborg via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Feb 16 01:40:28 PST 2017


On 2017-02-15 22:42, Andrew Chapman wrote:

> Thanks Jonathan.  Good point about the reference address.  I can work
> around this quite easily, but I was curious.  I will try the void* cast
> and see what happens.

If it's only for printing you can use the C "printf" without any casting:

import core.stdc.stdio;

class Node
{
     this()
     {
         printf("%p\n", this);
     }
}

void main()
{
     new Node;
}

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list