update: pointers log parser
This commit is contained in:
@ -43,6 +43,7 @@ func main() {
|
|||||||
|
|
||||||
fmt.Println("\n••••• CHANGE IN: passPtrVal")
|
fmt.Println("\n••••• CHANGE IN: passPtrVal")
|
||||||
passPtrVal(&counter) // same as passPtrVal(&counter) (no need to return)
|
passPtrVal(&counter) // same as passPtrVal(&counter) (no need to return)
|
||||||
|
passPtrVal(&counter) // same as passPtrVal(&counter) (no need to return)
|
||||||
fmt.Printf("counter : %-16d address: %-16p\n", counter, &counter)
|
fmt.Printf("counter : %-16d address: %-16p\n", counter, &counter)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,6 +54,9 @@ func passPtrVal(pn *int) {
|
|||||||
// pointers can breach function isolation borders
|
// pointers can breach function isolation borders
|
||||||
*pn++ // counter changes because `pn` points to `counter` — (*pn)++
|
*pn++ // counter changes because `pn` points to `counter` — (*pn)++
|
||||||
fmt.Printf("pn : %-16p address: %-16p *pn: %d\n", pn, &pn, *pn)
|
fmt.Printf("pn : %-16p address: %-16p *pn: %d\n", pn, &pn, *pn)
|
||||||
|
|
||||||
|
// setting it to nil doesn't effect the caller (the main function)
|
||||||
|
pn = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// n is a int variable (copy of counter)
|
// n is a int variable (copy of counter)
|
||||||
|
Reference in New Issue
Block a user