sure. you are right; but see, a (Node *) has no information about its (SV *). A workaround would be
typedef struct treeNode { char* name; char* desc; char* class; //in case we need it double branch_length; SV* obj; // the perlobj SV* obj_ref; // the ref to the perlobj struct treeNode *parent; } Node; SV* new(char* class, char* name, char* desc, double branch_length) { Node* node = malloc(sizeof(Node)); node->obj_ref = newSViv(0); node->obj = newSVrv(obj_ref, class); node->class = savepv(class); node->name = savepv(name); node->desc = savepv(desc); node->branch_length = branch_length; node->parent = NULL; // no parent yet sv_setiv(node->obj, (IV)node); SvREADONLY_on(node->obj); return node->obj_ref; } SV* get_parent(SV* obj) { Node *node = (Node *)SvIV(SvRV(obj)); if(node != NULL && node->parent != NULL) return node->parent->obj_ref; else return NULL; // not sure }
HTH

In reply to Re^3: Trees using Inline::C by esskar
in thread Trees using Inline::C by rvosa

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.