mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #6981 from ethereum/docs-purchase-contract
[DOCS] State default value of enum in example
This commit is contained in:
commit
3b0284817e
@ -298,8 +298,8 @@ Scoping and Declarations
|
|||||||
A variable which is declared will have an initial default value whose byte-representation is all zeros.
|
A variable which is declared will have an initial default value whose byte-representation is all zeros.
|
||||||
The "default values" of variables are the typical "zero-state" of whatever the type is. For example, the default value for a ``bool``
|
The "default values" of variables are the typical "zero-state" of whatever the type is. For example, the default value for a ``bool``
|
||||||
is ``false``. The default value for the ``uint`` or ``int`` types is ``0``. For statically-sized arrays and ``bytes1`` to ``bytes32``, each individual
|
is ``false``. The default value for the ``uint`` or ``int`` types is ``0``. For statically-sized arrays and ``bytes1`` to ``bytes32``, each individual
|
||||||
element will be initialized to the default value corresponding to its type. Finally, for dynamically-sized arrays, ``bytes``
|
element will be initialized to the default value corresponding to its type. For dynamically-sized arrays, ``bytes``
|
||||||
and ``string``, the default value is an empty array or string.
|
and ``string``, the default value is an empty array or string. For the ``enum`` type, the default value is its first member.
|
||||||
|
|
||||||
Scoping in Solidity follows the widespread scoping rules of C99
|
Scoping in Solidity follows the widespread scoping rules of C99
|
||||||
(and many other languages): Variables are visible from the point right after their declaration
|
(and many other languages): Variables are visible from the point right after their declaration
|
||||||
|
@ -13,6 +13,7 @@ Safe Remote Purchase
|
|||||||
address payable public seller;
|
address payable public seller;
|
||||||
address payable public buyer;
|
address payable public buyer;
|
||||||
enum State { Created, Locked, Inactive }
|
enum State { Created, Locked, Inactive }
|
||||||
|
// The state variable has a default value of the first member, `State.created`
|
||||||
State public state;
|
State public state;
|
||||||
|
|
||||||
// Ensure that `msg.value` is an even number.
|
// Ensure that `msg.value` is an even number.
|
||||||
|
@ -512,7 +512,7 @@ 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 conversion
|
to and from all integer types but implicit conversion is not allowed. The explicit conversion
|
||||||
from integer checks at runtime that the value lies inside the range of the enum and causes a failing assert otherwise.
|
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.
|
Enums require at least one member, and its default value when declared is the first 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``.
|
||||||
|
Loading…
Reference in New Issue
Block a user