josvazg
unread,Nov 25, 2010, 9:40:39 AM11/25/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to golang-nuts
Why is it that strings within a struct can't be set to nil?
In the samle below if I uncomment the str2 and its intiialization to
nil the compiler complains:
"structest.go:16: cannot use nil as type string in field value"
CODE...
_____________________________
package main
import (
"fmt"
"unsafe"
)
type somestruct struct {
someint int
somestr string
//str2 string
}
func main() {
fmt.Println("Hello, 世界")
s:=somestruct{1,"kk"/*,nil*/}
fmt.Println("somestruct:",s,"size",unsafe.Sizoef(s))
s.somestr="sdfs"
fmt.Println("somestruct:",s,"size",unsafe.Sizoef(s))
}