Last active
September 23, 2019 08:24
-
-
Save spytheman/673b733b1759d8eb1fefc82eb4e3f90a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 0[11:23:46] /v/v $ cat x.v | |
| struct Node { | |
| mut: | |
| head &Node | |
| tail &Node | |
| } | |
| fn (n Node) str() string { | |
| return 'node content: { head: $n.head , tail: $n.tail }' | |
| } | |
| fn print_node(label string, n &Node) { | |
| println('Node $label: ' + ptr_str(voidptr(n)) + ' : ' + n.str() ) | |
| } | |
| mut n1 := Node{} | |
| mut n2 := Node{} | |
| n1.tail = &n2 | |
| n2.head = &n1 | |
| print_node('n1', n1) | |
| print_node('n2', n2) | |
| n1.tail = &Node(voidptr(0)) | |
| print_node('n1', n1) | |
| 0[11:23:48] /v/v $ ./v run x.v | |
| Node n1: 0x7ffffabee4b0 : node content: { head: (nil) , tail: 0x7ffffabee4c0 } | |
| Node n2: 0x7ffffabee4c0 : node content: { head: 0x7ffffabee4b0 , tail: (nil) } | |
| Node n1: 0x7ffffabee4b0 : node content: { head: (nil) , tail: (nil) } | |
| 0[11:23:50] /v/v $ |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Setting the pointers to 0 after usage: