diff --git a/docs/contracts/constant-state-variables.rst b/docs/contracts/constant-state-variables.rst index 23da14a3c..fa1fd8c92 100644 --- a/docs/contracts/constant-state-variables.rst +++ b/docs/contracts/constant-state-variables.rst @@ -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; diff --git a/docs/layout-of-source-files.rst b/docs/layout-of-source-files.rst index 6c0dd0a16..afc6ce221 100644 --- a/docs/layout-of-source-files.rst +++ b/docs/layout-of-source-files.rst @@ -5,7 +5,8 @@ Layout of a Solidity Source File Source files can contain an arbitrary number of :ref:`contract definitions`, import_ directives, :ref:`pragma directives` and -:ref:`struct`, :ref:`enum` and :ref:`function` definitions. +:ref:`struct`, :ref:`enum`, :ref:`function` +and :ref:`constant variable` definitions. .. index:: ! license, spdx