aboutsummaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2016-06-09 00:09:18 +0800
committerchriseth <c@ethdev.com>2016-06-09 00:09:18 +0800
commit63b63056893717a9ec4565ba6c1e7c746592054b (patch)
tree2ac4d1e5347666a90075bf055a6100c1eacb31a4 /docs
parentfd64e3b7edc0a368fce9c7c8c967a9301c214a10 (diff)
parent4df076593408e1399fa2ea584cb27193f896de06 (diff)
downloaddexon-solidity-63b63056893717a9ec4565ba6c1e7c746592054b.tar
dexon-solidity-63b63056893717a9ec4565ba6c1e7c746592054b.tar.gz
dexon-solidity-63b63056893717a9ec4565ba6c1e7c746592054b.tar.bz2
dexon-solidity-63b63056893717a9ec4565ba6c1e7c746592054b.tar.lz
dexon-solidity-63b63056893717a9ec4565ba6c1e7c746592054b.tar.xz
dexon-solidity-63b63056893717a9ec4565ba6c1e7c746592054b.tar.zst
dexon-solidity-63b63056893717a9ec4565ba6c1e7c746592054b.zip
Merge pull request #618 from chriseth/inlineArrays
Document inline arrays.
Diffstat (limited to 'docs')
-rw-r--r--docs/types.rst38
1 files changed, 38 insertions, 0 deletions
diff --git a/docs/types.rst b/docs/types.rst
index 6a69f5be..9de83843 100644
--- a/docs/types.rst
+++ b/docs/types.rst
@@ -364,6 +364,44 @@ the ``.length`` member.
}
}
+.. index:: ! array;literals, !inline;arrays
+
+Array Literals / Inline Arrays
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Array literals are arrays that are written as an expression and are not
+assigned to a variable right away.
+
+::
+
+ contract C {
+ function f() {
+ g([uint(1), 2, 3]);
+ }
+ function g(uint[3] _data) {
+ // ...
+ }
+ }
+
+The type of an array literal is a memory array of fixed size whose base
+type is the common type of the given elements. The type of ``[1, 2, 3]`` is
+``uint8[3] memory``, because the type of each of these constants is ``uint8``.
+Because of that, it was necessary to convert the first element in the example
+above to ``uint``. Note that currently, fixed size memory arrays cannot
+be assigned to dynamically-sized memory arrays, i.e. the following is not
+possible:
+
+::
+
+ contract C {
+ function f() {
+ // The next line creates a type error because uint[3] memory
+ // cannot be converted to uint[] memory.
+ uint[] x = [uint(1), 3, 4];
+ }
+
+It is planned to remove this restriction in the future but currently creates
+some complications because of how arrays are passed in the ABI.
.. index:: ! array;length, length, push, !array;push