aboutsummaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
authorYoichi Hirai <i@yoichihirai.com>2017-03-15 17:03:35 +0800
committerGitHub <noreply@github.com>2017-03-15 17:03:35 +0800
commitd134fda0c05640992941087139316d2b8fb3f816 (patch)
treea26d7b2f78f6c167af83216545219d4e892f8e13 /docs
parent64e00e5371e2620a0bbd945d37e799e1e0309668 (diff)
parent9f328ff749477106a569e679e5eeed5c7e78d29d (diff)
downloaddexon-solidity-d134fda0c05640992941087139316d2b8fb3f816.tar.gz
dexon-solidity-d134fda0c05640992941087139316d2b8fb3f816.tar.zst
dexon-solidity-d134fda0c05640992941087139316d2b8fb3f816.zip
Merge pull request #1729 from ethereum/constantvariables
Only allow pure expressions for constant state variables.
Diffstat (limited to 'docs')
-rw-r--r--docs/contracts.rst26
1 files changed, 20 insertions, 6 deletions
diff --git a/docs/contracts.rst b/docs/contracts.rst
index 1516ba0b..9145f016 100644
--- a/docs/contracts.rst
+++ b/docs/contracts.rst
@@ -428,8 +428,25 @@ change by overriding).
Constant State Variables
************************
-State variables can be declared as constant (this is not yet implemented
-for array and struct types and not possible for mapping types).
+State variables can be declared as ``constant``. In this case, they have to be
+assigned from an expression which is a constant at compile time. Any expression
+that accesses storage, blockchain data (e.g. ``now``, ``this.balance`` or
+``block.number``) or
+execution data (``msg.gas``) or make calls to external contracts are disallowed. Expressions
+that might have a side-effect on memory allocation are allowed, but those that
+might have a side-effect on other memory objects are not. The built-in functions
+``keccak256``, ``sha256``, ``ripemd160``, ``ecrecover``, ``addmod`` and ``mulmod``
+are allowed (ever though they do call external contracts).
+
+The reason behind allowing side-effects on the memory allocator is that it
+should be possible to construct complex objects like e.g. lookup-tables.
+This feature is not yet fully usable.
+
+The compiler does not reserve a storage slot for these variables and every occurrence is
+replaced by the respective constant expression (which might be computed to a single value by the optimizer).
+
+Not all types for constants are implemented at this time. The only supported types are
+value types and strings.
::
@@ -438,12 +455,9 @@ for array and struct types and not possible for mapping types).
contract C {
uint constant x = 32**22 + 8;
string constant text = "abc";
+ bytes32 constant myHash = keccak256("abc");
}
-This has the effect that the compiler does not reserve a storage slot
-for these variables and every occurrence is replaced by their constant value.
-
-The value expression can only contain integer arithmetics.
******************
Constant Functions