10

What does the memory keyword in the argument of a function do?

pragma solidity 0.4.24;
pragma experimental "ABIEncoderV2";

contract Conditional {
struct Condition {
    address to;
    bytes4 selector;
    bytes parameters;
    bytes32 expectedValueHash;
    bool onlyCheckForSuccess;
  }

 function isSatisfied(Condition memory condition)
    public
    view
    returns (bool)
  {
    if (condition.onlyCheckForSuccess) {
      return assertNotFails(condition);
    } else {
      return assertReturnsExpectedResult(condition);
    }
  }

I understand what the memory keyword does. But what does it mean in the context of a function argument?

2 Answers 2

6

If you don't specify storage type of a function argument then function arguments are always in memory and you are passing an argument to a function by value.

When you are explicitly defining storage type of an argument asstorage you are passing an argument to a function by reference.

2
  • 3
    What is the purpose to specify a function argument as "memory" if all function arguments are by default "memory". It not redundant?
    – Deniz
    Jul 28, 2019 at 17:17
  • 1
    @Deniz, yes it is redundant. Jul 30, 2019 at 4:59
0

I think it is used to specify where the value is stored and when we make it memory it means that it will be put in temporary loc and will be there until the function is executed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.