github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/compiler/testdata/pointer.go (about) 1 package main 2 3 // This file tests various operations on pointers, such as pointer arithmetic 4 // and dereferencing pointers. 5 6 import "unsafe" 7 8 // Dereference pointers. 9 10 func pointerDerefZero(x *[0]int) [0]int { 11 return *x // This is a no-op, there is nothing to load. 12 } 13 14 // Unsafe pointer casts, they are sometimes a no-op. 15 16 func pointerCastFromUnsafe(x unsafe.Pointer) *int { 17 return (*int)(x) 18 } 19 20 func pointerCastToUnsafe(x *int) unsafe.Pointer { 21 return unsafe.Pointer(x) 22 } 23 24 func pointerCastToUnsafeNoop(x *byte) unsafe.Pointer { 25 return unsafe.Pointer(x) 26 }