 码农老张								  		后端
			  							2024-11-08
码农老张								  		后端
			  							2024-11-08
				
从定义可以看出nil是一个预定义的变量,并且是以下类型的变量:
指针、管道、函数、接口、Map、切片python
 代码解读复制代码// nil is a predeclared identifier representing the zero value for a
// pointer, channel, func, interface, map, or slice type.
var nil Type // Type must be a pointer, channel, func, interface, map, or slice type

runtime\malloc.gogo
 代码解读复制代码// base address for all 0-byte allocations
var zerobase uintptr
结构体本身和其字段都指向zerobase

空结构体字段和整个变量的地址及第二个字段的地址一样

空结构体字段的地址会紧跟前一个字节的末尾

空结构体字段的地址会紧跟前一个字节的末尾,但会进行填充,并且填充长度与前一个字段相同。

空接口的底层实现是eface,_type字段存储具体对象的类型,data字段存储具体对象的值rust
 代码解读复制代码type eface struct {
    _type *_type    // 
    data  unsafe.Pointer // 
}
细节:只有当eface的两个字段都为nil时,eface才为nil
