Why does the golang compiler not always get the address of the value?

for example, the golang compiler does not always get the address of the value


type Integer int 

func (i *Integer) pretty(){
 
}

Integer(25).pretty()//

ask for advice, why do you say so, under what circumstances can"t you find the pointer, and what is the principle

Mar.20,2021

because Integer (25). Pretty () will be optimized to an integer (constant) 25 call pretty function .

you should add a temporary variable, like this

n := Integer(25)
n.pretty()

  • it is reasonable that a constant cannot take a pointer. If a constant can get a pointer, it means that it can be modified and cannot be called a constant.
  • here is a blog post about go addressable .

golang so few people, only a few of you can be invited, thank you!

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bf3b46-31e81.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bf3b46-31e81.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?