Skip to content

Commit aac009e

Browse files
committed
Move utility function to module.
1 parent 27e0689 commit aac009e

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

examples/pipeline.f90

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ program main
1818
!! ```
1919
use :: nng
2020
use :: nng_pipeline0
21+
use :: nng_util
2122
implicit none (type, external)
2223

2324
character(80) :: message, name, url
@@ -32,14 +33,6 @@ program main
3233
case default; print '("Usage: pipeline node0|node1 <URL> <ARG> ...")'
3334
end select
3435
contains
35-
pure function f_c_str(f_str) result(c_str)
36-
!! In Fortran 2023, use `f_c_string()` instead.
37-
character(*), intent(in) :: f_str
38-
character(:), allocatable :: c_str
39-
40-
c_str = trim(f_str) // c_null_char
41-
end function f_c_str
42-
4336
subroutine fatal(rc, str)
4437
integer, intent(in) :: rc
4538
character(*), intent(in) :: str

src/nng_util.f90

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module nng_util
88
private
99

1010
public :: c_f_str_ptr
11+
public :: f_c_str
1112
contains
1213
subroutine c_f_str_ptr(c_str, f_str)
1314
!! Copies a C string, passed as a C pointer, to a Fortran string.
@@ -44,4 +45,15 @@ end function c_strlen
4445

4546
if (.not. allocated(f_str)) f_str = ''
4647
end subroutine c_f_str_ptr
48+
49+
pure function f_c_str(f_str) result(c_str)
50+
!! Converts Fortran string to C string. In Fortran 2023, use
51+
!! `f_c_string()` instead.
52+
use, intrinsic :: iso_c_binding, only: c_null_char
53+
54+
character(*), intent(in) :: f_str
55+
character(:), allocatable :: c_str
56+
57+
c_str = trim(f_str) // c_null_char
58+
end function f_c_str
4759
end module nng_util

0 commit comments

Comments
 (0)