progma solidity ^0.4.15;
contract Callee
{
uint public result_;
function foo (uint _length, uint[] _nums) public returns (uint)
{
result_ = 0;
for ( uint i = 0; i < _length; ++i)
result_ += _nums[i];
return result_;
}
}
contract Caller
{
uint public result_;
address public callee_ = <Address of deployed Callee>;
function Call (uint[] _nums) public returns (bool)
{ return callee_.delegatecall(bytes4(sha3("foo(uint256,uint256[])")), _nums.length, _nums); }
}
These are contracts I have defined. Deploy Callee
first, then give its address to Caller
contract, then invoke the Call
function with parameter [1]
, however the result_
value is 256 after calling.
I tested several data, and find out that each data in the uint256[]
param is left-shifted by 8 bits. But param 1, which has type uint256, is not shifted.
I want to know why.