On Thu, 10 May 2018 08:33:32 +0000 Jan Mercl <0xj...@gmail.com> wrote:
> This modified example from another thread does not compile: You modified it in a pretty significant way. The original example had type T = *T which is a recursive type alias (which is disallowed). Your new example has type T *T which is a recursive type which, while weird, is legal. The important thing to realise is that the second T in "type T *T" IS NOT an "int", has nothing to do with "int", does not even necessarily have the same storage size as "int". > > package main > > import ( > "fmt" > ) > > type T int > > func main() { > var v T v is effectively an int. On an LP64 platform that's a 32bit variable. > type T *T > var w T w is a pointer to a pointer to a pointer to ... NOT int. On an LP64 platform that's a 64bit variable. > w = &v On an LP64 platform &v is a pointer to a 32bit storage, while w is a pointer to a 64bit storage. There is no surprise that this assignment does not work. > *w = v > fmt.Printf("%T %T\n", v, w) > } > > https://play.golang.org/p/3wos23oim0I > > The compiler says > > prog.go:13:4: cannot use &v (type *T) as type T in assignment What the compiler means is cannot use &v (type *T_declared_outside_of_main_which_is_a_kind_of_int) as type T_declared_inside_main_which_is_a_type_of_pointer in assignment. MSB -- Wenn du dich mit einer Frau einlässt, verändert sich nicht die Frau. Die Frau verändert dich. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.