My function body looks like this:
function element(uint a, uint b, uint[2] memory c) public returns(uint e, uint f, uint g, uint k) {
I am wondering why do I put memory
keyword before c
? I know that the argument parameters are stored in calldata. so by using calldataload
, I successfully get a
and b
variables' values. The funny thing is by using calldataload
, I also managed to get c
(array) variable's first and second values.
So, turns out c
is also in calldata location. Why do we specify memory
then ?
memory
is explicitly stated. Obviously, non of the function arguments can ever reside in storage, so this is clearly just a redundant limitation added by the authors of the compiler (probably made it easier on them to parse the code). – goodvibration Oct 2 '20 at 16:10memory
only tells the compiler that an array/struct is not in storage, as implicitly assumed by the compiler. I have also explained that at the end of my answer to one of your previous questions, which you seem to have overlooked (or ignored). However, at the beginning of that same answer, I did state that the distinguish (between stack and heap) is based on primitive/non-primitive type rather than on known/unknown length. I'm not sure which one it is, and to a certain extent, these two definitions overlap. – goodvibration Oct 2 '20 at 16:50