1

Is it possible to use the name of the local variable of contract with sload code ?

contract Test {
  int a=999;
  function doIt() {
    assembly {
    sload(a);
    }
 }
}

1 Answer 1

2

Yes, although you may want to store the result of this load in a memory variable:

contract Test {
    int a = 999; // That's storage
    function doIt() {
        int b; // That's memory
        assembly {
            b := sload(a);
        }
    }
}
1
  • let b := sload(a) This will use stack instead of memory. Only drawback is that the variable can only be used inside the assembly block. Commented Aug 22, 2018 at 11:25

Your Answer

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

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