On Thu, Aug 27, 2020 at 3:53 AM targe...@gmail.com <target....@gmail.com> wrote:
>
> Please don't forget that interface pointer isn't simple. It's a so-called 
> "fat pointer" which consists of pointer to data and pointer to methods table. 
> Thus, we have 4 potential states - (nil, nil), (nil, pointer), (pointer, nil) 
> and (pointer,pointer). First one is just ordinary nil interface. Last one is 
> just ordinary interface pointer with all operations callable without issue 
> (as long as they're properly implemented, of course). Third one with valid 
> data pointer and nil table pointer can be AFAIK created only through 
> reflection and is safely considered "invalid state". We're left with second 
> state with nil data pointer and valid table pointer, making interface methods 
> callable on it. It wouldn't be a problem - if such state couldn't be created 
> by merely casting typed nil pointer (typed pointer variable with nil value) 
> to interface. Why is this an issue? Because most interface implementations 
> require valid data pointer. "Static" (i.e. not needing data) implementations 
> can be considered corner case.

Other people have said this too, but I want to emphasize that there
are not 4 potential states of an interface value.  There are 2
potential states: 1) interface does not hold any value, and is == nil;
2) interface holds a value, and is != nil.

When you start talking about an interface as a fat pointer you are
talking about how those 2 states are implemented.  There are other
possible implementations, and in fact the implementation in gccgo used
to be different.  And even the implementation in the gc compiler has
changed; at one time ints and other small values were stored directly
in the interface value, but now we instead store a pointer to the
data.

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/CAOyqgcWGy7nGqxbR9Gicf0owUB_eJWre0fTDzuUcX1yFNOO69A%40mail.gmail.com.

Reply via email to