-
-
Save hasanyasin/78707f1c84f36915bb77ce80209369df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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