OK, I want to make it clearer. Whether constants are untyped or typed, constants are treated at compile time and originary there is no idea of how much memory constants take but there is the idea of how much memory variables take so I should just focus on how much memory variables take at runtime. That's why for the examples below, the total memory usages are both "4" bytes respectably at runtime. Is it correct?
> 1. var num int32 = 100 > | > 4 bytes 2. var num int32 = int32(100) > | > 4 bytes 2019年1月31日木曜日 9時05分32秒 UTC+9 伊藤和也: > > An interger constant is "int" type and takes "8" bytes memory on 64-bit > system. > > fmt.Println(unsafe.Sizeof(100)) // 8 >> fmt.Println(reflect.TypeOf(100)) // int > > > and an "int32" type value takes "4" bytes. > > var num int32 >> fmt.Println(unsafe.Sizeof(num)) // 4 > > > So in this case below, Is the memory usage "12" bytes in total? (Question > 1) > > var num int32 = 100 >> | | >> 4 bytes + 8 bytes = 12 bytes > > > and in this case below, Is the memory usage "16" bytes in total? (Question > 2) > because the integer constant "100" is "8" bytes first then it's converted > to "int32" which is "4" bytes. > > var num int32 = int32(100) >> | | | >> 4 bytes + 4 bytes + 8 bytes = 16 bytes > > -- 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.