What\'s the cleanest way to handle a case such as this:
func a() string {
/* doesn\'t matter */
}
b *string = &a()
This generates the
The address operator returns a pointer to something having a "home", e.g. a variable. The value of the expression in your code is "homeless". if you really need a *string, you'll have to do it in 2 steps:
tmp := a(); b := &tmp
Note that while there are completely valid use cases for *string, many times it's a mistake to use them. In Go string
is a value type, but a cheap one to pass around (a pointer and an int). String's value is immutable, changing a *string
changes where the "home" points to, not the string value, so in most cases *string
is not needed at all.