module my_type interface my_cfunc module procedure my_cfunc1, my_cfunc2, my_cfunc3 end interface my_cfunc ! comment interface above and uncomment interface below to get working code !!$ interface my_cfunc !!$ module procedure my_cfunc1, my_cfunc3 !!$ end interface my_cfunc contains function my_cfunc1(s, i, sb, sa) integer(kind = 4) :: i character(len = :), allocatable :: my_cfunc1 integer(kind = 4), optional :: sb, sa character(len = *) :: s ! works: character length of result is not specified ! ... do something with arguments here my_cfunc1 = 'first' end function my_cfunc1 function my_cfunc2(s, i, n, sb, sa) integer(kind = 4) :: i, n character(len = n) :: my_cfunc2 integer(kind = 4), optional :: sb, sa character(len = *) :: s ! does not work: not distinguishable from my_cfunc1 although character length is a required arguments ! ... do something with arguments here my_cfunc2 = 'second' end function my_cfunc2 function my_cfunc3(n, s, i, sb, sa) integer(kind = 4) :: i, n character(len = n) :: my_cfunc3 integer(kind = 4), optional :: sb, sa character(len = *) :: s ! works: passed character length n is now the first argument ! ... do something with arguments here my_cfunc3 = 'third' end function my_cfunc3 end module my_type program main use my_type implicit none print *, my_cfunc('test', 1) read * end program main