Thread overview
how do I convert this C idiom?
Feb 19, 2003
Dan Liebgold
Feb 19, 2003
Dan Liebgold
Feb 19, 2003
Walter
February 19, 2003
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


February 19, 2003
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}
>];
>
>


February 19, 2003
They should both work; it's a compiler bug. -Walter