Documentation.

This commit is contained in:
chriseth 2020-09-30 21:31:28 +02:00
parent 34e7ae6ff9
commit df16515b52
2 changed files with 9 additions and 3 deletions

View File

@ -1,5 +1,7 @@
.. index:: ! constant
.. _constants:
**************************************
Constant and Immutable State Variables
**************************************
@ -9,6 +11,8 @@ In both cases, the variables cannot be modified after the contract has been cons
For ``constant`` variables, the value has to be fixed at compile-time, while
for ``immutable``, it can still be assigned at construction time.
It is also possible to define ``constant`` variables at the file level.
The compiler does not reserve a storage slot for these variables, and every occurrence is
replaced by the respective value.
@ -26,10 +30,11 @@ Not all types for constants and immutables are implemented at this time. The onl
::
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.7.0;
pragma solidity >0.7.2;
uint constant X = 32**22 + 8;
contract C {
uint constant X = 32**22 + 8;
string constant TEXT = "abc";
bytes32 constant MY_HASH = keccak256("abc");
uint immutable decimals;

View File

@ -5,7 +5,8 @@ Layout of a Solidity Source File
Source files can contain an arbitrary number of
:ref:`contract definitions<contract_structure>`, import_ directives,
:ref:`pragma directives<pragma>` and
:ref:`struct<structs>`, :ref:`enum<enums>` and :ref:`function<functions>` definitions.
:ref:`struct<structs>`, :ref:`enum<enums>`, :ref:`function<functions>`
and :ref:`constant variable<constants>` definitions.
.. index:: ! license, spdx