www.digitalmars.com         C & C++   DMDScript  

D - how do I convert this C idiom?

reply Dan Liebgold <Dan_member pathlink.com> writes:
In C/C++, I am used to building static data structures using pointers embedded
in the initializers, like so:


struct NODE {
int data;
NODE *next;
}

static NODE nodetbl[3] = [
{0,&nodetbl[1]},
{0,&nodetbl[2]},
{0,null}
];


How might I do this sort of thing in D, seeing as I must only use constant
initializers for arrays?

Thanks,
Dan
Feb 18 2003
parent reply Dan Liebgold <Dan_member pathlink.com> writes:
Of course, this seems to work:

static NODE nodetbl[3] = 
[
{0,(NODE*)nodetbl + 1},
{0,(NODE*)nodetbl + 2},
{0,null}
];

It does seem odd that ((NODE*)nodetbl + 1) is constant, but &nodetbl[1] is not.

Dan

In article <b2v4b4$1nti$1 digitaldaemon.com>, Dan Liebgold says...
In C/C++, I am used to building static data structures using pointers embedded
in the initializers, like so:


struct NODE {
int data;
NODE *next;
}

static NODE nodetbl[3] = [
{0,&nodetbl[1]},
{0,&nodetbl[2]},
{0,null}
];
Feb 18 2003
parent "Walter" <walter digitalmars.com> writes:
They should both work; it's a compiler bug. -Walter
Feb 19 2003