www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Re: is this the expected output

reply g g <htpp www.com> writes:
Thanks for the answers
what I did is this ( i feel that it is quite clumsy):

       Node* x = cast(Node*) (GC.malloc(Node.sizeof));
        *x = xa;
        x.up = curnode;
        ...
Dec 22 2010
next sibling parent spir <denis.spir gmail.com> writes:
On Wed, 22 Dec 2010 19:40:16 -0500
g g <htpp www.com> wrote:

 Thanks for the answers
 what I did is this ( i feel that it is quite clumsy):
=20
        Node* x =3D cast(Node*) (GC.malloc(Node.sizeof));
         *x =3D xa;
         x.up =3D curnode;
         ...

This is not that clumsy (except for you naming!). You have to allocate dist= inct memory cells for distinct programming elements that represent distinct= entities in your (mental) modell, haven't you? D provides adequate feature= s that allow you thinking thinking at a higher-level. But if you want to pl= ay at a lower-level, you'll need to juggle with pointer detail issues ;-) Denis -- -- -- -- -- -- -- vit esse estrany =E2=98=A3 spir.wikidot.com
Dec 22 2010
prev sibling parent Dmitry Olshansky <dmitry.olsh gmail.com> writes:
On 23.12.2010 3:40, g g wrote:
 Thanks for the answers
 what I did is this ( i feel that it is quite clumsy):

         Node* x = cast(Node*) (GC.malloc(Node.sizeof));
          *x = xa;
          x.up = curnode;
          ...

Node* x = new Node(...);//paste your constructor args in place of ... if Node has a constructor, or just Node* x = new Node;// if no constructors -- Dmitry Olshansky
Dec 23 2010