在原碼中的位置
/Users/Macbook/Documents/100 Work/100 Work PHP/php7internal/PHPtest/php-7.2.29/Zend/zend_types.h
struct _zval_struct {
zend_value value; /* value */
union {
struct {
ZEND_ENDIAN_LOHI_4( //大小端
zend_uchar type, /* active type */
zend_uchar type_flags,
zend_uchar const_flags,
zend_uchar reserved) /* call info for EX(This) */
} v;
uint32_t type_info;
} u1;
union {
uint32_t next; /* hash collision chain */
uint32_t cache_slot; /* literal cache slot */
uint32_t lineno; /* line number (for ast nodes) */
uint32_t num_args; /* arguments number for EX(This) */
uint32_t fe_pos; /* foreach position */
uint32_t fe_iter_idx; /* foreach iterator index */
uint32_t access_flags; /* class constant access flags */
uint32_t property_guard; /* single property guard */
uint32_t extra; /* not further specified */
} u2;
};
宏的使用
宏就是替換
在這裏,爲什麼要倒序輸入的值呢?
大小端
因爲PHP要在不同的地址上運行,所以要區分當前是大端機器,還是小端機器。
大端:把高位放在了低地址。
小端:把低位放在低地址。
宏的代碼測試
大小端的代碼測試
fun2利用聯合體的內存覆蓋原理,判斷大小端:
如果c=1,則說明低位在低內存地址。