I am having a little trouble creating pointers to maps in Go. Can you please let me know if I am passing the map parameter correctly? It pairs integer values with structs.
type symbol_table struct{
---
---
---
}
//is the map parameter being called correctly?
func TD(..., symbolMAP *map[int]symbol_table, ...){
---
---
---
}
func main(){
symbolMAP:=make(map[int] symbol_table)
TD(&symbolMAP)
}
Maps, like channels, but unlike slices, are just pointers to runtime types. As you saw above, a map is just a pointer to a runtime. hmap structure. Maps have the same pointer semantics as any other pointer value in a Go program.
Go programming language allows you to pass a pointer to a function. To do so, simply declare the function parameter as a pointer type.
No. Maps are reference by default.
As already noted in the comments, there is no need to pass pointer to a map.
A map is already a reference type. Changes in the map will be observed from other variables.
See also Q/A: Go - Pointer to map.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With