Most common run-time errors?

That is not safe either. You should assume that merge will evaluate both tsource and fsource. You need to use an if block. Because I have had the same problem with size I proposed making the size of an unallocated array -1. Peter Klausler suggested instead defining a safe wrapper for size

module mySizeModule
contains
pure integer function mySize(x)
class(*), dimension(..), intent(in), optional :: x
mySize = -1
if (present(x)) mySize = size(x)
end function
end module

use mySizeModule
integer, allocatable :: a(:), b(
allocate(a(10))
print *, mySize(a), mySize(b)
end

A previous thread was Size of an unallocated array

2 Likes