Standard library / reflect
reflect.NewAt()
Creates a pointer Value for existing correctly typed, aligned storage. Caller must ensure storage size, lifetime and validity; prefer ordinary New or ValueOf for normal use. Expected stdout: '9\n'.
Formal Syntax & Structure
go syntaxgo
func NewAt(typ Type, p unsafe.Pointer) ValueParameters & Attributes
| Name | Type | Description |
|---|---|---|
| typ | Type | Runtime type descriptor for the new value. |
| p | unsafe.Pointer | Pointer to live, correctly aligned storage matching the element type. |
Return Value
Value
Creates a pointer Value for existing correctly typed, aligned storage.
Working Example
Example Snippetgo
package main
import ( "fmt" "reflect" "unsafe")
func main() { x := 4 v := reflect.NewAt(reflect.TypeFor[int](), unsafe.Pointer(&x)) v.Elem().SetInt(9) fmt.Println(x)}