Translating Modula2 into D: variant records, pointer
Jarrett Billingsley
kb3ctd2 at yahoo.com
Tue Jan 9 07:18:05 PST 2007
"BLS" <Killing_Zoe at web.de> wrote in message
news:eo04h3$1us4$1 at digitaldaemon.com...
> Translating Modula2 into D: Subject: variant records,pointer
>
> Hi I have some Modula2 code which I would like to translate in D.
> I often have to use something like that :
> ...
> So: How do I have to implement this snippet in D ?
> Many thanks !!!! in advance; Bjoern
Something like:
module snippet;
struct Node
{
Node* suc;
Node* alt;
bool terminal;
union
{
char tsym;
Header* nSym;
}
}
struct Header
{
char sym;
Node* entry;
Header* suc;
}
Header* list;
Header* sentinel;
void Find(char s, inout Header* h)
{
Header* h1 = list;
sentinel.sym = s;
sentinel = new Header;
h = h1;
// etc.
}
One thing I'm not real sure on is the variant record. The closest thing I
think in D is a union, but nothing prevents you from accessing either tsym
or nSym in Node at any time. I guess in Modula2, if 'terminal' is true, you
can only access tsym, and otherwise you can only access nSym?
More information about the Digitalmars-d-learn
mailing list