Skip to content

Commit

Permalink
ctc
Browse files Browse the repository at this point in the history
  • Loading branch information
xhliu committed Feb 27, 2021
1 parent 1eff8b9 commit cdfb820
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
33 changes: 33 additions & 0 deletions docs/ctc.rst
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);
}
}
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ sCrypt is designed to facilitate writing smart contract running on chain.
loop
functions
contracts
ctc

.. toctree::
:maxdepth: 1
Expand Down

0 comments on commit cdfb820

Please sign in to comment.