使用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个字节的静态内存加载。"
不确定原因。在我看来,struct 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;
}
}
显然直接传递结构会导致编译错误,而传入单个字段则不会。想知道差异是什么。
答案 0 :(得分:1)
这似乎是一个可靠的错误 - 请参阅:
https://github.com/ethereum/solidity/issues/3361
和
https://github.com/ethereum/solidity/issues/3069
现在还有一个以太坊的Stack Exchange: