www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - _based pointers in D?

reply Robert <robert.muench robertmuench.de> writes:
Hi, is there a similar construct like a _based pointer in D?

type __based( base ) declarator

void *vpBuffer;

struct llist_t
{
    void __based( vpBuffer ) *vpData;
    struct llist_t __based( vpBuffer ) *llNext;
};

The pointer vpBuffer is assigned the address of memory allocated at 
some later point in the program. The linked list is relocated relative 
to the value of vpBuffer.
-- 
Robert M. Münch
http://www.robertmuench.de
Jun 03 2010
parent reply bearophile <bearophileHUGS lycos.com> writes:
Robert:
 Hi, is there a similar construct like a _based pointer in D?
This is a cute feature, more docs here: http://msdn.microsoft.com/en-us/library/57a97k4e.aspx D doesn't have this feature, but you can try to implement it using a struct that defines opUnary!("*") and more. If your implementation comes out nicely and you are willing to share your code, then maybe Andrei can add it to Phobos2. Bye, bearophile
Jun 04 2010
parent =?iso-8859-1?Q?Robert_M._M=FCnch?= <robert.muench robertmuench.de> writes:
On 2010-06-05 03:12:58 +0200, bearophile said:

 D doesn't have this feature, but you can try to implement it using a 
 struct that defines opUnary!("*") and more. If your implementation 
 comes out nicely and you are willing to share your code, then maybe 
 Andrei can add it to Phobos2.
Thanks for the hint using structs and the operator stuff. I will definetly look into it and share my stuff. I will need something like this in conjunction with memory-mapped-files. -- Robert M. Münch http://www.robertmuench.de
Jun 05 2010