type size in bytes
byte, uint8, int8 1
uint16, int16 2
uint32, int32, float32 4
uint64, int64, float64, complex64 8
complex128 16
type size in bytes
byte, uint8, int8 1
uint16, int16 2
uint32, int32, float32 4
uint64, int64, float64, complex64 8
complex128 16
package unsafe
type ArbitraryType int // shorthand for an arbitrary Go type; it is not a real type
type Pointer *ArbitraryType
func Alignof(variable ArbitraryType) uintptr
func Offsetof(selector ArbitraryType) uintptr
func Sizeof(variable ArbitraryType) uintptr
type IntegerType int // shorthand for an integer type; it is not a real type
func Add(ptr Pointer, len IntegerType) Pointer
func Slice(ptr *ArbitraryType, len IntegerType) []ArbitraryType
uintptr(unsafe.Pointer(&x)) % unsafe.Alignof(x) == 0
var f float64
bits = *(*uint64)(unsafe.Pointer(&f))
type ptr unsafe.Pointer
bits = *(*uint64)(ptr(&f))
var p ptr = nil
(*[len]ArbitraryType)(unsafe.Pointer(ptr))[:]
uintptr(unsafe.Pointer(&s)) + unsafe.Offsetof(s.f) == uintptr(unsafe.Pointer(&s.f))
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^= ~
type (
A1 = string
A2 = A1
)
type (
B1 string
B2 B1
B3 []B1
B4 B3
)
func f[P any](x P) { … }
type (
A0 = []string
A1 = A0
A2 = struct{ a, b int }
A3 = int
A4 = func(A3, float64) *A0
A5 = func(x int, _ float64) *[]string
B0 A0
B1 []string
B2 struct{ a, b int }
B3 struct{ a, c int }
B4 func(int, float64) *B0
B5 func(x int, y float64) *A1
C0 = B0
D0[P1, P2 any] struct{ x P1; y P2 }
E0 = D0[int, string]
)
a := 1
f := func() int { a++; return a }
x := []int{a, f()} // x may be [1, 2] or [2, 2]: evaluation order between a and f() is not specified
m := map[int]int{a: 1, a: 2} // m may be {2: 1} or {2: 2}: evaluation order between the two map assignments is not specified
n := map[int]int{a: f()} // n may be {2: 3} or {3: 3}: evaluation order between the key and the value is not specified
Recommend
The Go Programming Language Specification System considerations Package unsafe
The Go Programming Language Specification Run-time panics
The Go Programming Language Specification Errors
The Go Programming Language Specification Program initialization and execution Program execution
The Go Programming Language Specification Program initialization and execution The zero value
The Go Programming Language Specification Packages An example package
The Go Programming Language Specification Packages Import declarations
The Go Programming Language Specification Packages Package clause
The Go Programming Language Specification Packages Source file organization
The Go Programming Language Specification Built-in functions Bootstrapping
The Go Programming Language Specification Built-in functions Handling panics
The Go Programming Language Specification Built-in functions Manipulating complex numbers
The Go Programming Language Specification Built-in functions Deletion of map elements
The Go Programming Language Specification Built-in functions Appending to and copying slices
The Go Programming Language Specification Built-in functions Making slices, maps and channels
The Go Programming Language Specification Built-in functions Allocation
The Go Programming Language Specification Built-in functions Length and capacity
The Go Programming Language Specification Statements Defer statements
The Go Programming Language Specification Statements Fallthrough statements
The Go Programming Language Specification Statements Goto statements
The Go Programming Language Specification Statements Continue statements
The Go Programming Language Specification Statements Break statements
The Go Programming Language Specification Statements Return statements
The Go Programming Language Specification Statements Select statements
The Go Programming Language Specification Statements Go statements
The Go Programming Language Specification Statements For statements For statements with range clause
The Go Programming Language Specification Statements For statements For statements with for clause
The Go Programming Language Specification Statements For statements
The Go Programming Language Specification Statements Switch statements Type switches
The Go Programming Language Specification Statements Switch statements Expression switches
The Go Programming Language Specification Statements Switch statements
The Go Programming Language Specification Statements If statements
The Go Programming Language Specification Statements Assignments
The Go Programming Language Specification Statements IncDec statements
The Go Programming Language Specification Statements Send statements
The Go Programming Language Specification Statements Expression statements
The Go Programming Language Specification Statements Labeled statements
The Go Programming Language Specification Statements Empty statements
The Go Programming Language Specification Statements
The Go Programming Language Specification Expressions Order of evaluation
The Go Programming Language Specification Expressions Constant expressions