github.com/haraldrudell/parl@v0.4.176/uintptr.go (about)

     1  /*
     2  © 2022–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/)
     3  ISC License
     4  */
     5  
     6  package parl
     7  
     8  import "unsafe"
     9  
    10  // Uintptr returns v as a pointer
    11  //   - usable with [fmt.Printf] %x
    12  //   - if uintptr is not used, Printf may go off interpreting the value pointed to,
    13  //     depending on its type
    14  //
    15  // Usage:
    16  //
    17  //	var p = &SomeStruct{}
    18  //	parl.Log("p: 0x%x", parl.Uintptr(p))
    19  func Uintptr(v any) (p uintptr) {
    20  	return (*[2]uintptr)(unsafe.Pointer(&v))[1]
    21  }