I have some different structs like Big
with Small
embedded at offset 0.
How can I access Small
's structure fields from code, that doesn't know anything about Big
type, but it is known that Small
is at offset 0?
type Small struct {
val int
}
type Big struct {
Small
bigval int
}
var v interface{} = Big{}
// here i only know about 'Small' struct and i know that it is at the begining of variable
v.(Small).val // compile error
It seems that compiler is theoretically able to operate such expression, because it knows that Big
type has Small
type embedded at offset 0. Is there any way to do such things (maybe with unsafe.Pointer
)?