  MODULE test_mod
  USE ISO_C_BINDING, ONLY : C_PTR, C_CHAR, C_F_POINTER
  IMPLICIT none (external, type)
  PRIVATE
!
  PUBLIC :: C_F_STRPOINTER
!
  CONTAINS

  SUBROUTINE C_F_STRPOINTER(cstrPtr, fstrPtr, nchars)
  TYPE(C_PTR),INTENT(in)                            :: cstrPtr
  CHARACTER(KIND=C_CHAR, LEN=:),POINTER,INTENT(out) :: fstrPtr
  INTEGER,INTENT(in),OPTIONAL                       :: nChars
!
  ALLOCATE(CHARACTER(LEN=nchars) :: fstrPtr)
  CALL C_F_POINTER(cstrPtr, fstrPtr)                    !  <<<<<<<<<<<<<<<<<  problem line
!
  RETURN
  END SUBROUTINE C_F_STRPOINTER


  END MODULE test_mod
!
  PROGRAM test
  USE ISO_C_BINDING, ONLY : C_PTR, C_LOC, C_NULL_CHAR
  USE test_mod, ONLY      : C_F_STRPOINTER
  IMPLICIT none (external, type)
!
  CHARACTER(LEN=24),TARGET :: string
  TYPE(C_PTR)              :: pString
  CHARACTER(LEN=:),POINTER :: result
  INTEGER                  :: length
!
  string = "This is a test string!"//C_NULL_CHAR
  pString = C_LOC(string)
!
  CALL C_F_STRPOINTER(pString, result, 24)
  length = INDEX(result, C_NULL_CHAR)-1
!
  WRITE(*,*) "Result: ", result(1:length)
!
  END PROGRAM test