I would like to store an array of fixed size in my contract storage, with a user-defined size, initialized to all 0s. Here's an example contract:
pragma solidity ^0.4.24;
contract Test {
constructor(uint size) {
uint[size] storage arr;
for (uint i = 0; i < size; i++) { arr[i] = 0 }
}
}
My problem arises when declaring the array; remix gives this error:
TypeError: Invalid array length, expected integer literal or constant expression.
One workaround would be to declare the array outside of a function, but that would require it to be a dynamic array with no immediately accessible elements, which I don't want.
Is it possible to initialize arrays of this type in a constructor at all, and if so, how?
What's the alternate way to do the same?