ASSOCIATE and array bounds checking

Steve Kargl sgk@troutmask.apl.washington.edu
Sun Oct 30 20:21:00 GMT 2016


If I understand ASSOCIATE correctly, then the following 
code should issue a runtime error for an array mismatch.

program co_assoc

  implicit none

  integer, allocatable :: a(:)

  allocate (a(2))

  a = [1,2]
  write(*, '(5(I0,1X))') a, size(a), lbound(a), ubound(a)
 
  associate (i => a)
    i = i + 41
    write(*, '(5(I0,1X))') i, size(i), lbound(i), ubound(i)
    !
    ! i has dimensions i(1:2).  Array mismatch expression?
    ! 
    i = [1, 2, 3]
    write(*, '(5(I0,1X))') i, size(i), lbound(i), ubound(i)
  end associate

end program co_assoc

laptop-kargl:kargl[222] gfc -o z b.f90 && ./z
1 2 2 1 2
42 43 2 1 2
43 45 2 1 2

-- 
Steve



More information about the Fortran mailing list