5 openzeppelin的StorageSlot库中assembly { r.slot := slot } 什么意思

library StorageSlot {
    struct AddressSlot {
        address value;
    }

    struct BooleanSlot {
        bool value;
    }

    struct Bytes32Slot {
        bytes32 value;
    }

    struct Uint256Slot {
        uint256 value;
    }

    /**
     * @dev Returns an `AddressSlot` with member `value` located at `slot`.
     */
    function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
        assembly {
            r.slot := slot
        }
    }
}

汇编里slot变量都没有在struct中定义, 这样使用是什么意思?

请先 登录 后评论

最佳答案 2022-06-16 22:14

.slot 不是表示变量,就是表现指针对应的插槽位置。

比如类似的还有: .offset 表示偏移:

https://learnblockchain.cn/docs/solidity/assembly.html#access-to-external-variables-functions-and-libraries

请先 登录 后评论

其它 0 个回答

  • 1 关注
  • 1 收藏,1307 浏览
  • galuna 提出于 2022-06-16 19:22

相似问题