File: pointerToDeferredLengthString.F90

package info (click to toggle)
gftl 1.3.0%2Bis-really-1.2.7-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 1,328 kB
  • sloc: pascal: 4,163; f90: 3,551; sh: 27; fortran: 16; makefile: 2
file content (34 lines) | stat: -rw-r--r-- 536 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
module Foo_mod
   implicit none

   type Foo
      character(len=:), allocatable :: buffer
   contains
      procedure :: get
   end type Foo

contains

   function get(f) result(p)
      class (Foo), target, intent(in) :: f
      character(len=:), pointer :: p
      p => f%buffer
   end function get

end module Foo_mod

program main
   use Foo_mod
   implicit none
   
   character(len=:), pointer :: p
   type (Foo) :: f

   f%buffer = 'cat'
   p => f%get()

   if (.not. (p == 'cat')) then
      stop 1
   end if

end program main