diff options
author | Chris Ward <chriswhward@gmail.com> | 2018-11-15 18:59:37 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2018-12-03 18:49:42 +0800 |
commit | 78ca2801d8a63769bbd8cff5948c4b92d693d11c (patch) | |
tree | 63179e5cc7a4d2916864d5d1d851ad7db28bc3d0 /docs/types.rst | |
parent | 0d1dd30ce84e77866e648219f4c84129fcb497e6 (diff) | |
download | dexon-solidity-78ca2801d8a63769bbd8cff5948c4b92d693d11c.tar.gz dexon-solidity-78ca2801d8a63769bbd8cff5948c4b92d693d11c.tar.zst dexon-solidity-78ca2801d8a63769bbd8cff5948c4b92d693d11c.zip |
Move String literal and inline array FAQ items
Fix tab
Update docs/types.rst
Co-Authored-By: ChrisChinchilla <chriswhward@gmail.com>
Update docs/types.rst
Co-Authored-By: ChrisChinchilla <chriswhward@gmail.com>
Diffstat (limited to 'docs/types.rst')
-rw-r--r-- | docs/types.rst | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/docs/types.rst b/docs/types.rst index 69c846a6..f67a6d1a 100644 --- a/docs/types.rst +++ b/docs/types.rst @@ -465,11 +465,13 @@ a non-rational number). .. index:: literal, literal;string, string .. _string_literals: -String Literals ---------------- +String Literals and Types +------------------------- String literals are written with either double or single-quotes (``"foo"`` or ``'bar'``). They do not imply trailing zeroes as in C; ``"foo"`` represents three bytes, not four. As with integer literals, their type can vary, but they are implicitly convertible to ``bytes1``, ..., ``bytes32``, if they fit, to ``bytes`` and to ``string``. +For example, with ``bytes32 samevar = "stringliteral"`` the string literal is interpreted in its raw byte form when assigned to a ``bytes32`` type. + String literals support the following escape characters: - ``\<newline>`` (escapes an actual newline) @@ -862,13 +864,20 @@ or create a new memory array and copy every element. } } -.. index:: ! array;literals, !inline;arrays +.. index:: ! array;literals, ! inline;arrays + +Array Literals +^^^^^^^^^^^^^^ + +An array literal is a comma-separated list of one or more expressions, enclosed +in square brackets (``[...]``). For example ``[1, a, f(3)]``. There must be a +common type all elements can be implicitly converted to. This is the elementary +type of the array. -Array Literals / Inline Arrays -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Array literals are always statically-sized memory arrays. -Array literals are arrays that are written as an expression and are not -assigned to a variable right away. +In the example below, the type of ``[1, 2, 3]`` is +``uint8[3] memory``. Because the type of each of these constants is ``uint8``, if you want the result to be a ``uint[3] memory`` type, you need to convert the first element to ``uint``. :: @@ -883,13 +892,7 @@ assigned to a variable right away. } } -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 is 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: +Fixed size memory arrays cannot be assigned to dynamically-sized memory arrays, i.e. the following is not possible: :: @@ -904,8 +907,8 @@ possible: } } -It is planned to remove this restriction in the future but currently creates -some complications because of how arrays are passed in the ABI. +It is planned to remove this restriction in the future, but it creates some +complications because of how arrays are passed in the ABI. .. index:: ! array;length, length, push, pop, !array;push, !array;pop |