if the target variable in the caller contract is in slot 0, the returned value will be the slot 0 of the delegatedcalled contract.
For instance:
contract caller {
uint public number;
address public callerAddress;
function delegatecallSetNumber(address delegatedAddress, uint256 _number) public {
delegatedAddress.delegatecall(bytes4(keccak256("setNumber(uint256)")), _number);
}
}
contract delegatedcalled {
uint public number;
address public callerAddress;
function setNumber(uint _number) public {
number = _number;
callerAddress = msg.sender;
}
}
1.
After the delegate call, the value number in the caller will be the value in the slot 0 (number) of the delegatecalled contract.
2.
If we modify the delegatecalled contract like this:
contract delegatedcalled {
address public callerAddress;
uint public number;
function setNumber(uint _number) {
number = _number;
callerAddress = msg.sender;
}
}
The variable number in the caller will have the slot 0 in the delegatecalled contract (the address)
3.
Changing the name of the variables in the delegatedcalled contract have no effect in the result, the contract below will still work identically as in 1 (see above)
contract delegatedcalled {
uint public numberxxxx;
address public callerAddress;
function setNumber(uint _number) {
numberxxxx = _number;
callerAddress = msg.sender;
}
}
Hope this helps you