mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Document storage variable access.
This commit is contained in:
parent
e64a03d86b
commit
a46a059e3a
@ -323,9 +323,12 @@ Access to External Variables and Functions
|
|||||||
------------------------------------------
|
------------------------------------------
|
||||||
|
|
||||||
Solidity variables and other identifiers can be accessed by simply using their name.
|
Solidity variables and other identifiers can be accessed by simply using their name.
|
||||||
For storage and memory variables, this will push the address and not the value onto the
|
For memory variables, this will push the address and not the value onto the
|
||||||
stack. Also note that non-struct and non-array storage variable addresses occupy two slots
|
stack. Storage variables are different: Values in storage might not occupy a
|
||||||
on the stack: One for the address and one for the byte offset inside the storage slot.
|
full storage slot, so their "address" is composed of a slot and a byte-offset
|
||||||
|
inside that slot. To retrieve the slot pointed to by the variable ``x``, you
|
||||||
|
used ``x_slot`` and to retrieve the byte-offset you used ``x_offset``.
|
||||||
|
|
||||||
In assignments (see below), we can even use local Solidity variables to assign to.
|
In assignments (see below), we can even use local Solidity variables to assign to.
|
||||||
|
|
||||||
Functions external to inline assembly can also be accessed: The assembly will
|
Functions external to inline assembly can also be accessed: The assembly will
|
||||||
@ -340,17 +343,13 @@ changes during the call, and thus references to local variables will be wrong.
|
|||||||
|
|
||||||
.. code::
|
.. code::
|
||||||
|
|
||||||
pragma solidity ^0.4.0;
|
pragma solidity ^0.4.11;
|
||||||
|
|
||||||
contract C {
|
contract C {
|
||||||
uint b;
|
uint b;
|
||||||
function f(uint x) returns (uint r) {
|
function f(uint x) returns (uint r) {
|
||||||
assembly {
|
assembly {
|
||||||
b pop // remove the offset, we know it is zero
|
r := mul(x, sload(b_slot)) // ignore the offset, we know it is zero
|
||||||
sload
|
|
||||||
x
|
|
||||||
mul
|
|
||||||
=: r // assign to return variable r
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user