小编suh*_*asa的帖子

为什么取消引用地址会在 golang 中产生“无效的间接”错误?

type person struct{
  Name string
  Age int
}

// parameters : (pointer to person struct), which is basically address of person object
func printPerson(p *person) {

  // when we add '*' to a address, then it becomes dereferencing, Hence 
  // I read "*p.Name" as "person object dot Name" and i expect it to give value,
  // I get this error:
  // ./prog.go:20:15: invalid indirect of p.Name (type string)
  // ./prog.go:20:24: invalid indirect of p.Age (type int)
  fmt.Println(*p.Name, *p.Age) // does …
Run Code Online (Sandbox Code Playgroud)

pointers go memory-address dereference

2
推荐指数
1
解决办法
297
查看次数

Why declaring a channel in global scope gives deadlock issue

Out of 3 code snippets, the one with channels declared in local scope works, other code snippets gives deadlock issue, One of the previously answered SO question here says try to avoid declaring channel in the global scope. I checked in the official docs, but I didn't find any explanation.

  1. Why is the global scope channel giving an error although I am not blocking the channel from sending and receiving? why am I getting a deadlock issue here?

  2. How …

concurrency deadlock scope channel go

1
推荐指数
1
解决办法
49
查看次数