Say we have the following structure:
struct MyStruct {
uint256 x;
uint256 y;
}
and that it is passed as an argument to some function. Inside that function, we have assembly
block from where we try to access x
and y
:
function myFunc(MyStruct memory data) internal view returns (bool) {
// (...)
assembly {
let args := mload(0x40);
mstore(args, data.x);
mstore(args, data.y);
// (...)
}
// (...)
}
And the compilation fails with:
Error: CompileError: ParsedContract.sol:404:28: ParserError: Expected ')' but got '.'
mstore(args, data.x)
Is it not allowed? Is there any workaround? I want to avoid creating temporary uint256
fields to avoid additional gas expenses.
mload(data)
should be the first field, andmload(add(data, 0x20))
the second, etc.mload
allows for this. Is it the same for a nested structure?struct MyStruct {point x, point y}
andstruct point { uint256 x, uint256 y}
? I am trying to do it the same way withmload(data)
,mload(add(data, 0x20))
, then0x40
,0x60
but with no success.