2

使用 Remix ( https://remix.ethereum.org/ ) 并使用 struct。编译器是0.4.19+commit.c4cbbb05. “优化”未选中。

pragma solidity ^0.4.4;

contract Test {
    struct FooBar {
        uint8 foo;
        uint16 bar;
    }

    FooBar public fooBar;

    function getFooBar() public view returns(FooBar) {
        return fooBar;
    }

    function setFooBar(FooBar value) public {
        fooBar = value;
    }
}

它显示错误:“InternalCompilerError:请求的静态内存负载超过 32 个字节。”

不知道为什么。在我看来,结构FooBar只有 3 个字节大。我的两个函数都读取/写入单个FooBar. 我在这里想念什么?

更新

稍微重构一下代码以使其更清晰:

pragma solidity ^0.4.4;

contract Test {
    struct FooBar {
        uint8 foo;
        uint16 bar;
    }

    FooBar public fooBar;

    // InternalCompilerError: Static memory load of more than 32 bytes requested.
    function setFooBar1(FooBar value) public {
        fooBar = value;
    }

    // No such error.
    function setFooBar2(uint8 foo, uint16 bar) public {
        fooBar.foo = foo;
        fooBar.bar = bar;
    }
}

显然,直接传递结构会导致编译错误,而传递单个字段则不会。想知道有什么区别。

4

1 回答 1

1

这似乎是一个可靠的错误 - 请参阅:

https://github.com/ethereum/solidity/issues/3361

和:

https://github.com/ethereum/solidity/issues/3069

现在还有一个用于以太坊的 Stack Exchange:

https://ethereum.stackexchange.com/

于 2018-01-09T02:17:51.363 回答