-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
===================== | ||
Compile Time Constant | ||
===================== | ||
A compile time constant (CTC) is a value that can be computed at compile time. There are two types of compile time constants. | ||
* literals | ||
* static constants which are initialized with a literal | ||
|
||
There are two cases where only compile time constants are allowed. | ||
* loop bound | ||
* array size | ||
|
||
.. code-block:: solidity | ||
contract CTC { | ||
static const int N = 4; | ||
static const int LOOPCOUNT = 30; | ||
// A is not a CTC because the right hand size is an expression, not a literal | ||
static const int A = 2 + 1; | ||
// B is not a CTC because it is not static | ||
const int B = 2; | ||
public function unlock(int y) { | ||
int[N] arr = [1, 2, 3, 4]; | ||
int z = 0; | ||
loop (LOOPCOUNT) | ||
{ | ||
if (z<y) z += 4; | ||
} | ||
require(y == 1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters