| --- |
| title: InvalidOffsetof |
| layout: article |
| --- |
| <!-- Copyright 2023 The Go Authors. All rights reserved. |
| Use of this source code is governed by a BSD-style |
| license that can be found in the LICENSE file. --> |
| |
| <!-- Code generated by generrordocs.go; DO NOT EDIT. --> |
| |
| ``` |
| InvalidOffsetof occurs when unsafe.Offsetof is called with a method |
| selector, rather than a field selector, or when the field is embedded via |
| a pointer. |
| |
| Per the spec: |
| |
| "If f is an embedded field, it must be reachable without pointer |
| indirections through fields of the struct. " |
| |
| Example: |
| import "unsafe" |
| |
| type T struct { f int } |
| type S struct { *T } |
| var s S |
| var _ = unsafe.Offsetof(s.f) |
| |
| Example: |
| import "unsafe" |
| |
| type S struct{} |
| |
| func (S) m() {} |
| |
| var s S |
| var _ = unsafe.Offsetof(s.m) |
| ``` |
| |