BitCast

Reinterprets the bits of a value as another type.

Declaration

Syntax

BitCast(expr source, expr mold, expr? size, ttype type, expr? value)

Arguments

Argument

Description

source

the value whose bits are taken.

mold

a value of the target type; it is not read, only its type is used.

size

the number of elements of the result, when it is an array; nil otherwise.

type

the type of the result.

value

the compile time value of the expression, when the frontend could fold it; nil otherwise.

Return values

The value of the expression.

Description

transfer(source, mold). Nothing is converted: the bits are copied and read as the new type, so transferring a real(4) to an integer(4) gives its representation rather than its value. Cast is the node that converts.

Examples

(BitCast
  :source (Var
    :v (SymbolRef 1 "x")
  )
  :mold (Var
    :v (SymbolRef 1 "i")
  )
  :size nil
  :type (Integer
    :kind 4
  )
  :value nil
)

It comes from this complete ASR text document:

(TranslationUnit
  :symtab (SymbolTable
    :id 0
    :symbols {
      "main" (Program
        :symtab (SymbolTable
          :id 1
          :symbols {
            "i" (Variable
              :parent_symtab 1
              :name "i"
              :dependencies []
              :intent :Local
              :symbolic_value nil
              :value nil
              :storage :Default
              :type (Integer
                :kind 4
              )
              :type_declaration nil
              :abi :Source
              :access :Public
              :presence :Required
              :value_attr false
              :target_attr false
              :contiguous_attr false
              :bindc_name nil
              :is_volatile false
              :is_protected false
              :pass_attr :NotMethod
              :self_argument nil
              :codims []
            )
            "x" (Variable
              :parent_symtab 1
              :name "x"
              :dependencies []
              :intent :Local
              :symbolic_value nil
              :value nil
              :storage :Default
              :type (Real
                :kind 4
              )
              :type_declaration nil
              :abi :Source
              :access :Public
              :presence :Required
              :value_attr false
              :target_attr false
              :contiguous_attr false
              :bindc_name nil
              :is_volatile false
              :is_protected false
              :pass_attr :NotMethod
              :self_argument nil
              :codims []
            )
          }
        )
        :name "main"
        :dependencies []
        :body [
          (Assignment
            :target (Var
              :v (SymbolRef 1 "i")
            )
            :value (BitCast
              :source (Var
                :v (SymbolRef 1 "x")
              )
              :mold (Var
                :v (SymbolRef 1 "i")
              )
              :size nil
              :type (Integer
                :kind 4
              )
              :value nil
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
        ]
      )
    }
  )
  :items []
)

See Also

Cast, SizeOfType, CLoc