Golang 学习
编译命令build
在cmd 中输入go build helloworld.go,将在当前目录下生成helloworld.exe。
map注意点
- 使用for range访问map时,每次访问的次序都是随机的。每次使用for range访问map,都会得到不同的结果。
- go中的map 实现是哈希表hashmap。源码阅读文件:
(GOROOT/Go/src/runtime/hashmap.go)
rune
rune 是int32 的别名。用UTF-8 进行编码。这个类型在什么时候使用呢?例如需要遍
历字符串中的字符。可以循环每个字节(仅在使用US ASCII 编码字符串时与字符等价,
而它们在Go 中不存在!)。因此为了获得实际的字符,需要使用rune 类型。
在UTF-8 世界的字符有时被称作runes。通常,当人们讨论字符时,多数是指8 位字符。UTF-8 字符可能会有32 位,称作rune。
转载自:
http://blog.163.com/hehaifeng1984@126/blog/static/690011362015715935516/
go语言数据类型与c语言相应类型对应关系
char --> C.char --> byte
signed char --> C.schar --> int8
unsigned char --> C.uchar --> uint8
short int --> C.short --> int16
short unsigned int --> C.ushort --> uint16
int --> C.int --> int
unsigned int --> C.uint --> uint32
long int --> C.long --> int32 or int64
long unsigned int --> C.ulong --> uint32 or uint64
long long int --> C.longlong --> int64
long long unsigned int --> C.ulonglong --> uint64
float --> C.float --> float32
double --> C.double --> float64
wchar_t --> C.wchar_t -->
void * -> unsafe.Pointer