On Tuesday, August 21, 2018 at 7:08:43 PM UTC-4, Carl Mastrangelo wrote:
>
> The answer must be more nuanced than that, because it is possible to take 
> a nil pointer and construct an unsafe.Pointer from it.  
>
> The reason I am interested in this is (and please don't judge too early) 
> is I'm toying around with implementing some atomic primitives.  In 
> particular, I would like to play around with with the cmpxchg16b 
> instruction which needs 16 byte alignment.   Go does not provide a way to 
> enforce a data structure has such alignment, so I am attempting to define a 
> struct that I can index into.  (assume 64bit words).  For example, the 
> datastructure I want is this:
>
> // alignment of foo is 16
> type foo struct {
>   uintptr
>   unsafe.Pointer
> }
>
>
 Carl,

Here is a simple attempt to provide you with a pointer to a 16-byte aligned 
Foo struct for your cmpxchg16b instruction experiments. See the NewFoo() 
function. Fields, including hidden fields, are initialized to the zero 
value for the type: zero for uintptr and nil for unsafe.Pointer.

Playground: https://play.golang.org/p/_nVltTdS5kS

Peter

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to