0
4 |             character(100) :: to_upper
  |                                           1

Error: Explicit interface required for 'to_upper' at (1): result with non-constant character length

    program main

        implicit none

        character(100) :: to_upper

        character(100) :: some_str

        some_str = "hello world"

        some_str = to_upper(some_str)

    end program main

    pure function to_upper (str) Result (string)
       ! Changes a string to upper case
        implicit None

        Character(*), Intent(In) :: str
        Character(LEN(str))      :: string
       ! An algorithm goes here... 
    end function
  • I asked this q. before and the above is what was suggested.... Thanks – Steve Lord Jan 10 '23 at 20:56
  • 1
    The error message tells you that you need an explicit interface. We have several questions with answers explaining what an explicit interface is. The best practice is to place all your subroutines and functions in modules. Or you can make them internal by placing them after `contains` but before `end program`. Also, please use the tag [tag:fortran] for Fortran questions. – Vladimir F Героям слава Jan 10 '23 at 21:42
  • Better duplicate: https://stackoverflow.com/questions/24910843/defining-a-function-returning-an-array – Vladimir F Героям слава Jan 10 '23 at 21:46
  • 1
    Although the linked question is about array results, the answers apply equally to character results with non-constant lengths. If you do need clarification on the very subtle differences, please [edit] your question with that focus. Also note that the error isn't about the argument passed _to_ the function. And finally, the `character(100) :: to_upper` declaration is horribly close to an entirely different [concept](https://stackoverflow.com/questions/42791082/a) altogether. Never do this. (The explicit interface solves this problem, too.) – francescalus Jan 10 '23 at 21:56

0 Answers0