Skip to content

Latest commit

 

History

History
26 lines (25 loc) · 1.85 KB

Types.md

File metadata and controls

26 lines (25 loc) · 1.85 KB

Types

  1. Solidity is statically types e.g uint256 value, you need to declare types
  2. This is the order of precedence of operations
  3. The concept of undefined of null DOES NOT EXIST in solidity
  4. Newly declared variables always have a default value dependent on its type
  5. To handle unexpected values, you shout use the revert() function, to revert the whole transaction, or return a tuple with a secind bool value denoting success (value, bool) =
  6. Value Types:
    1. Booleans: True of False
    2. Opearators:
      1. ! - logical negation
      2. && - logical conjunction, and
      3. || - logical disjuntion or
      4. == - equality
      5. != - inequality

        Note: The operators || and && apply the common short-circuitung rules. This means that expressiong f(x) || g(y), if f(x) evaluates to true, g(y)will not be evaluated even if it may have side-effects.

    3. Integers
      1. int or uint signed and unsigned integers of various sizes, uint8 to uint256 in steps of 8
      2. Operators:
        1. Comparisons: <=, <, ==, !=, >=, > - evaluate to bool
        2. Bit operators: &, |, ^ (exclusive or - xor), ~ (bitwise negation)
        3. Shift operators: <<, >>

          The righy operand must be of uinsigned type, trying to shift by signed type will produce a compilation error. x << y $\equiv$ x * 2**y, x >> y $\equiv$ x / 2**y, Warning: Overflow checks are never performed for shift operations as they are done for arithmetic operations. Instead the result is truncated.

        4. Arithmetic operators: +, -, - unary (only for signed integers), *, /, %, **
        5. for integer X, type(X).min and type(X).max for minimum and maximum values presentable by the type