CPtrToPointer

Converts a C pointer into a Fortran pointer.

Declaration

Syntax

CPtrToPointer(expr cptr, expr ptr, expr? shape, expr? lower_bounds)

Arguments

Argument

Description

cptr

the c_ptr value to convert.

ptr

the Fortran pointer that is made to point at it.

shape

the shape the pointer takes when it is an array pointer.

lower_bounds

the lower bounds of that shape; nil means all ones.

Return values

None.

Description

This is c_f_pointer. It is a statement rather than an expression because it associates a pointer, and because the shape of the target is supplied here rather than being known from the C pointer, which carries no shape at all.

PointerToCPtr is the other direction, and CLoc takes the address of a target.

Examples

(CPtrToPointer
  :cptr (Var
    :v (SymbolRef 1 "c")
  )
  :ptr (Var
    :v (SymbolRef 1 "p")
  )
  :shape (Var
    :v (SymbolRef 1 "shape")
  )
  :lower_bounds nil
)

It comes from this complete ASR text document:

(TranslationUnit
  :symtab (SymbolTable
    :id 0
    :symbols {
      "main" (Program
        :symtab (SymbolTable
          :id 1
          :symbols {
            "c" (Variable
              :parent_symtab 1
              :name "c"
              :dependencies []
              :intent :Local
              :symbolic_value nil
              :value nil
              :storage :Default
              :type (CPtr)
              :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 []
            )
            "p" (Variable
              :parent_symtab 1
              :name "p"
              :dependencies []
              :intent :Local
              :symbolic_value nil
              :value nil
              :storage :Default
              :type (Pointer
                :type (Array
                  :type (Integer
                    :kind 4
                  )
                  :dims [
                    (dimension
                      :start nil
                      :length nil
                    )
                  ]
                  :physical_type :DescriptorArray
                )
              )
              :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 []
            )
            "shape" (Variable
              :parent_symtab 1
              :name "shape"
              :dependencies []
              :intent :Local
              :symbolic_value nil
              :value nil
              :storage :Default
              :type (Array
                :type (Integer
                  :kind 4
                )
                :dims [
                  (dimension
                    :start (IntegerConstant
                      :n 1
                      :type (Integer
                        :kind 4
                      )
                      :intboz_type :Decimal
                    )
                    :length (IntegerConstant
                      :n 1
                      :type (Integer
                        :kind 4
                      )
                      :intboz_type :Decimal
                    )
                  )
                ]
                :physical_type :FixedSizeArray
              )
              :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 [
          (CPtrToPointer
            :cptr (Var
              :v (SymbolRef 1 "c")
            )
            :ptr (Var
              :v (SymbolRef 1 "p")
            )
            :shape (Var
              :v (SymbolRef 1 "shape")
            )
            :lower_bounds nil
          )
        ]
      )
    }
  )
  :items []
)

See Also

PointerToCPtr, CLoc, CPtr, Associate