type, public :: timer_t private real :: savedTime contains private procedure :: StartTimer => StartTimerSub procedure :: ElapsedTime => ElapsedTimeFun end type timer_t
subroutine StartTimerSub(this) class(timer_t) :: this this%savedTime = 0.0 end subroutine StartTimerSub
function ElapsedTimeFun(this) result(retVal) class(timer_t) :: this real :: retVal retVal = 1.0 - this%savedTime end function ElapsedTimeFun
end module Timer_c
program TestTimer use Timer_c implicit none type(timer_t) :: t
call t%StartTimer() write(*, *) t%ElapsedTime()
end program TestTimer
Both StartTimer and ElapsedTime are declared as private, but the compiler give only one error that ElapsedTime is private, StartTimer is still accessible in main program. That means functions are handled correctly, not subroutines. However, in gfortran compilers, both errors are detected. I think this is a bug.