You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are some types in Solidity's type system that have no counterpart in the syntax. One of these types are the types of functions. But still, using ``var`` it is possible to have local variables of these types::
146
-
147
-
contract FunctionSelector {
148
-
function select(bool useB, uint x) returns (uint z) {
149
-
var f = a;
150
-
if (useB) f = b;
151
-
return f(x);
152
-
}
153
-
154
-
function a(uint x) returns (uint z) {
155
-
return x * x;
156
-
}
157
-
158
-
function b(uint x) returns (uint z) {
159
-
return 2 * x;
160
-
}
161
-
}
162
-
163
-
Calling ``select(false, x)`` will compute ``x * x`` and ``select(true, x)`` will compute ``2 * x``.
164
-
165
140
.. index:: optimizer, common subexpression elimination, constant propagation
0 commit comments