Standard library / go/types
go/types.StdSizes.Offsetsof()
Returns byte offsets for fields in declaration order; a negative offset signals excessive size. Expected stdout: '[0 8]\n'.
Formal Syntax & Structure
go syntaxgo
func (s *StdSizes) Offsetsof(fields []*Var) []int64Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| fields | []*Var | Field variables in declaration order. |
Return Value
[]int64
Returns byte offsets for fields in declaration order; a negative offset signals excessive size.
Working Example
Example Snippetgo
package main
import ( "fmt" "go/types")
func main() { v := &types.StdSizes{WordSize: 8, MaxAlign: 8} fs := []*types.Var{types.NewField(0, nil, "A", types.Typ[types.Uint8], false), types.NewField(0, nil, "B", types.Typ[types.Int64], false)} fmt.Println(v.Offsetsof(fs))}