diff options
author | Chris Ward <chriswhward@gmail.com> | 2018-11-15 19:11:25 +0800 |
---|---|---|
committer | Chris Ward <chriswhward@gmail.com> | 2018-11-15 19:11:25 +0800 |
commit | 9b657134ef33a5a01dd09d8fcd7a13922bb7aaa4 (patch) | |
tree | 3492dc82f2574ac678d418c630201fd863a71828 | |
parent | 9db76403bb378e3b36bde8b42794ad6da0262ec9 (diff) | |
download | dexon-solidity-9b657134ef33a5a01dd09d8fcd7a13922bb7aaa4.tar dexon-solidity-9b657134ef33a5a01dd09d8fcd7a13922bb7aaa4.tar.gz dexon-solidity-9b657134ef33a5a01dd09d8fcd7a13922bb7aaa4.tar.bz2 dexon-solidity-9b657134ef33a5a01dd09d8fcd7a13922bb7aaa4.tar.lz dexon-solidity-9b657134ef33a5a01dd09d8fcd7a13922bb7aaa4.tar.xz dexon-solidity-9b657134ef33a5a01dd09d8fcd7a13922bb7aaa4.tar.zst dexon-solidity-9b657134ef33a5a01dd09d8fcd7a13922bb7aaa4.zip |
Remove length related FAQ item
-rw-r--r-- | docs/frequently-asked-questions.rst | 44 | ||||
-rw-r--r-- | docs/types.rst | 4 |
2 files changed, 3 insertions, 45 deletions
diff --git a/docs/frequently-asked-questions.rst b/docs/frequently-asked-questions.rst index 8b655b0d..985d8d3c 100644 --- a/docs/frequently-asked-questions.rst +++ b/docs/frequently-asked-questions.rst @@ -325,50 +325,6 @@ to create an independent copy of the storage value in memory. On the other hand, ``h(x)`` successfully modifies ``x`` because only a reference and not a copy is passed. -Sometimes, when I try to change the length of an array with ex: ``arrayname.length = 7;`` I get a compiler error ``Value must be an lvalue``. Why? -================================================================================================================================================== - -You can resize a dynamic array in storage (i.e. an array declared at the -contract level) with ``arrayname.length = <some new length>;``. If you get the -"lvalue" error, you are probably doing one of two things wrong. - -1. You might be trying to resize an array in "memory", or - -2. You might be trying to resize a non-dynamic array. - -:: - - pragma solidity >=0.4.18 <0.6.0; - - // This will not compile - contract C { - int8[] dynamicStorageArray; - int8[5] fixedStorageArray; - - function f() public { - int8[] memory memArr; // Case 1 - memArr.length++; // illegal - - int8[5] storage storageArr = fixedStorageArray; // Case 2 - storageArr.length++; // illegal - - int8[] storage storageArr2 = dynamicStorageArray; - storageArr2.length++; // legal - - - } - } - -**Important note:** In Solidity, array dimensions are declared backwards from the way you -might be used to declaring them in C or Java, but they are access as in -C or Java. - -For example, ``int8[][5] somearray;`` are 5 dynamic ``int8`` arrays. - -The reason for this is that ``T[5]`` is always an array of 5 ``T``'s, -no matter whether ``T`` itself is an array or not (this is not the -case in C or Java). - Is it possible to return an array of strings (``string[]``) from a Solidity function? ===================================================================================== diff --git a/docs/types.rst b/docs/types.rst index 020cb105..b84d3222 100644 --- a/docs/types.rst +++ b/docs/types.rst @@ -913,7 +913,9 @@ Members For dynamically-sized arrays (only available for storage), this member can be assigned to resize the array. Accessing elements outside the current length does not automatically resize the array and instead causes a failing assertion. Increasing the length adds new zero-initialised elements to the array. - Reducing the length performs an implicit :ref:``delete`` on each of the removed elements. + Reducing the length performs an implicit :ref:``delete`` on each of the + removed elements. If you try to resize a non-dynamic array that isn't in + storage, you receive a ``Value must be an lvalue`` error. **push**: Dynamic storage arrays and ``bytes`` (not ``string``) have a member function called ``push`` that you can use to append an element at the end of the array. The element will be zero-initialised. The function returns the new length. **pop**: |