diff options
author | Daniel Kirchner <daniel@ekpyron.org> | 2018-07-03 21:20:59 +0800 |
---|---|---|
committer | Daniel Kirchner <daniel@ekpyron.org> | 2018-07-10 17:38:33 +0800 |
commit | 65631cffc2127fc603371c67f85d2c07da07c3ca (patch) | |
tree | a6f0de8c9b0d494d1801de22735fd9f3b3a8061f /docs | |
parent | 46d6454b1f47e53c791d71aba26bb953ec667433 (diff) | |
download | dexon-solidity-65631cffc2127fc603371c67f85d2c07da07c3ca.tar dexon-solidity-65631cffc2127fc603371c67f85d2c07da07c3ca.tar.gz dexon-solidity-65631cffc2127fc603371c67f85d2c07da07c3ca.tar.bz2 dexon-solidity-65631cffc2127fc603371c67f85d2c07da07c3ca.tar.lz dexon-solidity-65631cffc2127fc603371c67f85d2c07da07c3ca.tar.xz dexon-solidity-65631cffc2127fc603371c67f85d2c07da07c3ca.tar.zst dexon-solidity-65631cffc2127fc603371c67f85d2c07da07c3ca.zip |
Update documentation and Changelog.
Diffstat (limited to 'docs')
-rw-r--r-- | docs/frequently-asked-questions.rst | 47 |
1 files changed, 5 insertions, 42 deletions
diff --git a/docs/frequently-asked-questions.rst b/docs/frequently-asked-questions.rst index 0d6fa033..75693bdd 100644 --- a/docs/frequently-asked-questions.rst +++ b/docs/frequently-asked-questions.rst @@ -306,48 +306,11 @@ independent copy of the state variable is created in memory and is another issue). The modifications to this independent copy do not carry back to ``data1`` or ``data2``. -A common mistake is to declare a local variable and assume that it will -be created in memory, although it will be created in storage:: - - /// THIS CONTRACT CONTAINS AN ERROR - - pragma solidity ^0.4.0; - - contract C { - uint someVariable; - uint[] data; - - function f() public { - uint[] x; - x.push(2); - data = x; - } - } - -The type of the local variable ``x`` is ``uint[] storage``, but since -storage is not dynamically allocated, it has to be assigned from -a state variable before it can be used. So no space in storage will be -allocated for ``x``, but instead it functions only as an alias for -a pre-existing variable in storage. - -What will happen is that the compiler interprets ``x`` as a storage -pointer and will make it point to the storage slot ``0`` by default. -This has the effect that ``someVariable`` (which resides at storage -slot ``0``) is modified by ``x.push(2)``. - -The correct way to do this is the following:: - - pragma solidity ^0.4.0; - - contract C { - uint someVariable; - uint[] data; - - function f() public { - uint[] x = data; - x.push(2); - } - } +.. warning:: + Prior to version 0.5.0, a common mistake was to declare a local variable and assume that it will + be created in memory, although it will be created in storage. Using such a variable without initializing + it could lead to unexpected behavior. Starting from 0.5.0, however, storage variables have to be initialized, + which should prevent these kinds of mistakes. ****************** Advanced Questions |