Could someone explain to me what exactly happens when I declare a storage pointer?
This example highlights the issue that I have encountered:
contract minimum {
uint256[] a = [1,2,3,4];
function createOffersAsList() public returns (uint256[]) {
uint256[] storage b;
uint256 i = 0;
Logger("Before loop", b);
// What I expected it to return: '"Before loop", ""'
// What it actually returns: '"Before loop", "1, 2, 3, 4"'
while (i<4) {
b.push(a[i]);
i++;
}
Logger("After loop", b);
return b;
// What I expected it to return: '"After loop", "1, 2, 3, 4"'
// What it actually returns: '"After loop", "1, 2, 3, 4, 1, 2, 3, 4"'
}
event Logger(string s, uint256[] u);
}
It seems to me, that when I declare b that it is automatically assigned to the storage of a. Why is that? I would have thought that it is just assigned to some free space?
And if I need to use a local dynamically sized array, how would this look like?
Thanks in advance and best regards, carbee