Passing element of an optional array as optional scalar argument

@FedericoPerini ,

No, it does not conform to the standard but the onus lies on the program author; the processor is not required to detect and report the nonconformance.

Starting Fortran 2008, an option that conforms to the standard and which you may consider is as follows:

subroutine optnl_array(array)
   integer, intent(in), optional :: array(10)
   integer, allocatable :: a
   if ( present(array) ) a = array(5) 
   call optnl_scalar( a ) ! An unallocated object can be passed as an OPTIONAL argument
end subroutine optnl_array

subroutine optnl_scalar(s)
   integer, intent(in), optional :: s 
   ..
4 Likes