mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Last part of value types.
This commit is contained in:
parent
785cbf4005
commit
32362f1b38
@ -398,9 +398,37 @@ a non-rational number).
|
|||||||
String Literals
|
String Literals
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
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``.
|
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``.
|
||||||
|
|
||||||
String literals support escape characters, such as ``\n``, ``\xNN`` and ``\uNNNN``. ``\xNN`` takes a hex value and inserts the appropriate byte, while ``\uNNNN`` takes a Unicode codepoint and inserts an UTF-8 sequence.
|
String literals support the following escape characters:
|
||||||
|
|
||||||
|
- ``\<newline>`` (escapes an actual newline)
|
||||||
|
- ``\\`` (backslash)
|
||||||
|
- ``\'`` (single quote)
|
||||||
|
- ``\"`` (double quote)
|
||||||
|
- ``\b`` (backspace)
|
||||||
|
- ``\f`` (form feed)
|
||||||
|
- ``\n`` (newline)
|
||||||
|
- ``\r`` (carriage return)
|
||||||
|
- ``\t`` (tab)
|
||||||
|
- ``\v`` (vertical tab)
|
||||||
|
- ``\xNN`` (hex escape, see below)
|
||||||
|
- ``\uNNNN`` (unicode escape, see below)
|
||||||
|
|
||||||
|
``\xNN`` takes a hex value and inserts the appropriate byte, while ``\uNNNN`` takes a Unicode codepoint and inserts an UTF-8 sequence.
|
||||||
|
|
||||||
|
The string in the following example has a length of ten bytes.
|
||||||
|
It starts with a newline byte, followed by a double quote, a single
|
||||||
|
quote a backslash character and then (without separator) the
|
||||||
|
character sequence ``abcdef``.
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
"\n\"\'\\abc\
|
||||||
|
def"
|
||||||
|
|
||||||
|
Any unicode line terminator which is not a newline (i.e. LF, VF, FF, CR, NEL, LS, PS) is considered to
|
||||||
|
terminate the string literal. Newline only terminates the string literal if it is not preceded by a ``\``.
|
||||||
|
|
||||||
.. index:: literal, bytes
|
.. index:: literal, bytes
|
||||||
|
|
||||||
@ -419,8 +447,9 @@ Enums
|
|||||||
-----
|
-----
|
||||||
|
|
||||||
Enums are one way to create a user-defined type in Solidity. They are explicitly convertible
|
Enums are one way to create a user-defined type in Solidity. They are explicitly convertible
|
||||||
to and from all integer types but implicit conversion is not allowed. The explicit conversions
|
to and from all integer types but implicit conversion is not allowed. The explicit conversion
|
||||||
check the value ranges at runtime and a failure causes an exception. Enums needs at least one member.
|
from integer checks at runtime that the value lies inside the range of the enum and causes a failing assert otherwise.
|
||||||
|
Enums needs at least one member.
|
||||||
|
|
||||||
The data representation is the same as for enums in C: The options are represented by
|
The data representation is the same as for enums in C: The options are represented by
|
||||||
subsequent unsigned integer values starting from ``0``.
|
subsequent unsigned integer values starting from ``0``.
|
||||||
@ -488,6 +517,11 @@ omitted. Note that this only applies to function types. Visibility has
|
|||||||
to be specified explicitly for functions defined in contracts, they
|
to be specified explicitly for functions defined in contracts, they
|
||||||
do not have a default.
|
do not have a default.
|
||||||
|
|
||||||
|
Conversions:
|
||||||
|
|
||||||
|
A value of external function type can be explicitly converted to ``address``
|
||||||
|
resulting in the address of the contract of the function.
|
||||||
|
|
||||||
A function type ``A`` is implicitly convertible to a function type ``B`` if and only if
|
A function type ``A`` is implicitly convertible to a function type ``B`` if and only if
|
||||||
their parameter types are identical, their return types are identical,
|
their parameter types are identical, their return types are identical,
|
||||||
their internal/external property is identical and the state mutability of ``A``
|
their internal/external property is identical and the state mutability of ``A``
|
||||||
@ -497,7 +531,7 @@ is not more restrictive than the state mutability of ``B``. In particular:
|
|||||||
- ``view`` functions can be converted to ``non-payable`` functions
|
- ``view`` functions can be converted to ``non-payable`` functions
|
||||||
- ``payable`` functions can be converted to ``non-payable`` functions
|
- ``payable`` functions can be converted to ``non-payable`` functions
|
||||||
|
|
||||||
No other conversions are possible.
|
No other conversions between function types are possible.
|
||||||
|
|
||||||
The rule about ``payable`` and ``non-payable`` might be a little
|
The rule about ``payable`` and ``non-payable`` might be a little
|
||||||
confusing, but in essence, if a function is ``payable``, this means that it
|
confusing, but in essence, if a function is ``payable``, this means that it
|
||||||
@ -517,7 +551,9 @@ Note that public functions of the current contract can be used both as an
|
|||||||
internal and as an external function. To use ``f`` as an internal function,
|
internal and as an external function. To use ``f`` as an internal function,
|
||||||
just use ``f``, if you want to use its external form, use ``this.f``.
|
just use ``f``, if you want to use its external form, use ``this.f``.
|
||||||
|
|
||||||
Additionally, public (or external) functions also have a special member called ``selector``,
|
Members:
|
||||||
|
|
||||||
|
Public (or external) functions also have a special member called ``selector``,
|
||||||
which returns the :ref:`ABI function selector <abi_function_selector>`::
|
which returns the :ref:`ABI function selector <abi_function_selector>`::
|
||||||
|
|
||||||
pragma solidity ^0.4.16;
|
pragma solidity ^0.4.16;
|
||||||
|
Loading…
Reference in New Issue
Block a user