Skip to content

Instantly share code, notes, and snippets.

@hasanyasin
Last active October 2, 2019 22:06
Show Gist options
  • Save hasanyasin/78707f1c84f36915bb77ce80209369df to your computer and use it in GitHub Desktop.
Save hasanyasin/78707f1c84f36915bb77ce80209369df to your computer and use it in GitHub Desktop.
const std = @import("std");
const log = std.debug.warn;
pub const Node = struct {
j:u64,
};
pub const ElementNode = struct {
i:u64,
node:Node,
firstChild:?*Node = undefined,
pub fn New(i:u64) *Node {
var d = ElementNode{.i=i, .node=Node{.j=i+32}};
log("Element : {} i:{}, node.j:{}\n", @ptrToInt(&d.node), d.i, d.node.j);
return &d.node;
}
};
pub fn main() void {
var node = ElementNode.New(19);
var child = ElementNode.New(339);
var np = @fieldParentPtr(ElementNode, "node", node).*;
var cp = @fieldParentPtr(ElementNode, "node", child).*;
log("Node : {} i:{}, node.j:{}\n", @ptrToInt(node), np.i, node.j);
log("Child: {} i:{}, node.j:{}\n", @ptrToInt(child), np.i, child.j);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment