原文:http://golang.org/doc/go_spec.html
    翻译:红猎人 (zengsai@gmail.com)

Boolean types
布尔类型

truefalsebool

Numeric types
数字类型

numeric type represents sets of integer or floating-point values. The predeclared architecture-independent numeric types are:
数字类型表明一个数字或浮点值的集合。预约义的类型是:golang

uint8       the set of all unsigned  8-bit integers (0 to 255)
uint16 the set of all unsigned 16-bit integers (0 to 65535) uint32 the set of all unsigned 32-bit integers (0 to 4294967295) uint64 the set of all unsigned 64-bit integers (0 to 18446744073709551615) int8 the set of all signed 8-bit integers (-128 to 127) int16 the set of all signed 16-bit integers (-32768 to 32767) int32 the set of all signed 32-bit integers (-2147483648 to 2147483647) int64 the set of all signed 64-bit integers (-9223372036854775808 to 9223372036854775807) float32 the set of all IEEE-754 32-bit floating-point numbers float64 the set of all IEEE-754 64-bit floating-point numbers complex64 the set of all complex numbers with float32 real and imaginary parts complex128 the set of all complex numbers with float64 real and imaginary parts byte familiar alias for uint8

The value of an n-bit integer is n bits wide and represented using two's complement arithmetic.express

There is also a set of predeclared numeric types with implementation-specific sizes:less

uint     either 32 or 64 bits int      either 32 or 64 bits float    either 32 or 64 bits complex  real and imaginary parts have type float uintptr  an unsigned integer large enough to store the uninterpreted bits of a pointer value
byteuint8int32int

String types

string
bytes[i]&s[i]slens

Array types

An array is a numbered sequence of elements of a single type, called the element type. The number of elements is called the length and is never negative.spa

ArrayType   = "[" ArrayLength "]" ElementType . ArrayLength = Expression . ElementType = Type .
alen(a)len(a)-1
[32]byte [2*N] struct { x, y int32 } [1000]*float64 [3][5]int [2][2][2]float64  // same as [2]([2]([2]float64))

Slice types

nil
SliceType = "[" "]" ElementType .
slen(s)len(s)-1

A slice, once initialized, is always associated with an underlying array that holds its elements. A slice therefore shares storage with its array and with other slices of the same array; by contrast, distinct arrays always represent distinct storage.

acap(a)len()cap()
0 <= len(a) <= cap(a)
nilnilTmake
make([]T, length) make([]T, length, capacity)
make()
make([]T, length, capacity)

produces the same slice as allocating an array and slicing it, so these two examples result in the same slice:

make([]int, 50, 100) new([100]int)[0:50]
make

阅读全文
类别:Golang 查看评论