On Fri, Jul 19, 2019 at 4:33 PM <ju...@sqreen.io> wrote:
>
> I would like to make sure that the following line of Go is a defined behavior:
>
>  addr := (*unsafe.Pointer)((unsafe.Pointer)(&ptr))
>
> I use it to perform atomic loads and stores to addr such as in this simple 
> example: https://play.golang.org/p/DpDrRvTYMG8
> It allows me not to use atomic.Value which performs two atomic operations and 
> possible disable preemption 
> (https://golang.org/src/sync/atomic/value.go?s=1233:1269#L35).

Yes, that operation is defined.  As documented at
https://golang.org/pkg/unsafe, you can use unsafe.Pointer to convert
from a pointer to one type to a pointer to a different type.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcUq65RATwbr6z9RNthxqcJTEPwtVyiQXjU_04TpOKWKLw%40mail.gmail.com.

Reply via email to