ソロidity-3.定数

768 ワード

定数(constant state variables) は、constant として定義されてもよく、javaのstatic静的変数と同様に、定数は以下のように規定されています。
  • は、すべてのタイプが定数をサポートしているわけではなく、現在サポートされているのは および だけである。
  • constant は、コンパイル中に1つの表現による値付け
  • をしなければならない。
  • コンパイラはconstant のためにstorageに空間
  • を残しておくことはできません。
    pragma solidity ^0.4.0;
    
    contract C {
        uint constant x = 32**22 + 8;
        string constant text = "abc";
        bytes32 constant myHash = keccak256("abc");
    }
    
    常関数(Content Functions)
    関数は、ブロックチェーン上の任意の状態を変更しないことを約束します。
    pragma solidity ^0.4.0;
    
    contract C {
        function f(uint a, uint b) constant returns (uint) {
            return a * (b + 42);
        }
    }