Yes. From the spec <https://golang.org/ref/spec#Address_operators>:

For an operand x of pointer type *T, the pointer indirection *x denotes *the
> variable* of type T pointed to by x.


Emphasis mine. "The variable", means it really denotes the storage location
that `x` points to. Not the value or anything like that. Further, then:

For an operand x of type T, the address operation &x generates a pointer of
> type *T to x. The operand must be addressable, that is, either a variable, 
> *pointer
> indirection*, or slice indexing operation; or a field selector of an
> addressable struct operand; or an array indexing operation of an
> addressable array. *As an exception to the addressability requirement, x
> may also be a (possibly parenthesized) composite literal*.


Emphasis mine, again. This tells you that the behavior of `&` with
composite literals to allocate a new variable is an exception - in general,
`&` just gives you the address of whatever expression you apply it to. In
this case, specifically, a pointer-indirection denoting, as we've seen
above, the *variable* that x points to.

So, it is completely expected that `&(*p) == p`.

On Wed, Aug 4, 2021 at 5:18 PM Olivier Szika <szika.oliv...@gmail.com>
wrote:

> Hi all,
>
> I am surprised by the behavior of "&(*var)".
>
> https://play.golang.org/p/CK522lRkddd
>
> It is expected?
>
> --
> 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/5f265699-ed67-4798-92d0-88832a7444d1n%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/5f265699-ed67-4798-92d0-88832a7444d1n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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/CAEkBMfGYofdV4cd%3DZXC%2B5itONTKog9KP7ELQHNBGBjoQ8yENYw%40mail.gmail.com.

Reply via email to