This question is connected to the problem: how to detect violation of intent(in) inside subprograms. But I haven’t found the answer in the related question Enforce intent(in) declared variables in Fortran as constant also in called subroutines/functions.
A variable which is declared as intent(in) can be modified by another subprogram/function with omitted intent declaration.
For example:
module test
implicit none
contains
subroutine fun1(x)
real(8), intent(in)::x
call fun2(x)
end subroutine
subroutine fun2(x)
real(8) :: x
x = 10
end subroutine
end module
This code can be compiled without any errors/warnings by gfortran and ifort. So my questions are:
- Is it possible to forbid omitting intent declaration?
- Is it possible to force a Fortran compiler to interpret omitted intent as
intent(inout)?
Both answers are NO. Unspecified intent is fundamentally different from all other intents. It is different from intent(inout), because you can pass a nondefinable expression to a subroutine with unspecified intent.
Also in many contexts it is not allowed to specify intent at all (procedure arguments, pointers in Fortran 95,…)
If you want to require specifying of intent, you may define your subroutine as
purebut it does much more than that. But it may be the right thing for you. It forbids any side-effects.