您的位置:首页 > 编程语言 > Go语言

golang中的byte、rune对应的基础类型

2018-07-30 23:11 316 查看

golang中存在丰富的类型,其中一部分类型如byte、rune等是基于底层的整形等基础类型实现的,熟悉类型对应的基础类型能够帮助我们了解一些coding中的小技巧,可以基于类型的基础类型直接使用。
首先了解一下一些内建类型对应的基础类型,这些都可以在源码中builtin.go中找到:

// byte is an alias for uint8 and is equivalent to uint8 in all ways. It is
// used, by convention, to distinguish byte values from 8-bit unsigned
// integer values.
type byte = uint8

// rune is an alias for int32 and is equivalent to int32 in all ways. It is
// used, by convention, to distinguish character values from integer values.
type rune = int32

// iota is a predeclared identifier representing the untyped integer ordinal
// number of the current const specification in a (usually parenthesized)
// const declaration. It is zero-indexed.
const iota = 0 // Untyped int.

如下一些小技巧:

s:="abc"
cs := make([]int, 128)
for _, c := range s {
cs[c] += 1
}
阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: