Compile Time Constants
An introduction to the concept and usage of Compile Time Constants (CTCs).
Compile Time Constants (CTCs) are values that can be calculated at compile time. There are four types of compile time constants:
Literals
Induction variables
Static constant properties of a contract initialized with literals
Static constant function parameters
There are several cases where only compile time constants can be used:
Loop boundaries
Array sizes
Writing to array elements using the indexing operator
Declaring static constant function parameters, such as
size
inreverseBytes(bytes b, static const int size)
andrepeat(T e, static const int size)
Note: Order matters: when declaring function parameters, const static
is not allowed, but it is allowed when declaring properties.