This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

(l|u)bound mess


On Linux AMD64 the following program

program type_array_section

type der_type
    real x
    integer :: in
end type der_type

type :: thytype
    integer(4) :: a(2,2)
end type thytype

type :: mytype
    integer(4), dimension(2,2) :: a
    type(thytype), dimension(2) :: q
end type mytype

type(der_type), dimension(0:4), target  :: typ
type (mytype) :: x
integer :: b(2,2) = reshape ((/42, 99, 55, 77/), (/2,2/))
type (thytype) :: foo
integer :: y(0:1, -1:0) = reshape ((/42, 99, 55, 77/), (/2,2/))
integer       , dimension(:)  , pointer :: pt_1
integer       , dimension(0:4)          :: iarr

foo = thytype(b)
typ%in =  45
typ%x  =  3.
pt_1 => typ%in
iarr   = 45
x = mytype(y, (/foo, foo/))

print *,' lbound(x%a ,1), ubound(x%a ,1)       ', lbound(x%a,1),ubound(x%a,1)
print *,' lbound(y ,1), ubound(y ,1)           ', lbound(y,1),ubound(y,1)
print *,' lbound(x%a ,2), ubound(x%a ,2)       ', lbound(x%a,2),ubound(x%a,2)
print *,' lbound(y ,2), ubound(y ,2)          ', lbound(y,2),ubound(y,2)

print *,' lbound(typ), ubound(typ)             ', lbound(typ),ubound(typ)
print *,' lbound(typ(:)), ubound(typ(:))       ', lbound(typ(:)),ubound(typ(:))
print *,' lbound(typ%in), ubound(typ%in)       ', lbound(typ%in),ubound(typ%in)
print *,' lbound(typ(:)%in), ubound(typ(:)%in) ', lbound(typ(:)%in),ubound(typ(:)%in)
print *,' lbound(pt_1), ubound(pt_1)           ', lbound(pt_1),ubound(pt_1)
print *,' lbound(pt_1(:)), ubound(pt_1(:))     ', lbound(pt_1(:)),ubound(pt_1(:))
print *,' lbound(iarr), ubound(iarr)           ', lbound(iarr),ubound(iarr)
print *,' lbound(iarr(:)), ubound(iarr(:))     ', lbound(iarr(:)),ubound(iarr(:))
print *,' lbound(iarr(2:3)), ubound(iarr(2:3)) ', lbound(iarr(2:3)),ubound(iarr(2:3))

end program type_array_section

gives with Intel(R) Fortran Compiler for 32-bit applications, Version 8.1:

  lbound(x%a ,1), ubound(x%a ,1)                  1            2
  lbound(y ,1), ubound(y ,1)                      0            1
  lbound(x%a ,2), ubound(x%a ,2)                  1            2
  lbound(y ,2), ubound(y ,2)                     -1            0
  lbound(typ), ubound(typ)                        0            4
  lbound(typ(:)), ubound(typ(:))                  1            5
  lbound(typ%in), ubound(typ%in)                  1            5
  lbound(typ(:)%in), ubound(typ(:)%in)            1            5
  lbound(pt_1), ubound(pt_1)                      1            5
  lbound(pt_1(:)), ubound(pt_1(:))                1            5
  lbound(iarr), ubound(iarr)                      0            4
  lbound(iarr(:)), ubound(iarr(:))                1            5
  lbound(iarr(2:3)), ubound(iarr(2:3))            1            2

with pgf (aka pgf90) 6.0-2 64-bit target on x86-64 Linux:

  lbound(x%a ,1), ubound(x%a ,1)                   1            2
  lbound(y ,1), ubound(y ,1)                       0            1
  lbound(x%a ,2), ubound(x%a ,2)                   1            2
  lbound(y ,2), ubound(y ,2)                      -1            0
  lbound(typ), ubound(typ)                         0            4
  lbound(typ(:)), ubound(typ(:))                   1            5
  lbound(typ%in), ubound(typ%in)                   0            4        *
  lbound(typ(:)%in), ubound(typ(:)%in)             0            4        *
  lbound(pt_1), ubound(pt_1)                       0            4        *
  lbound(pt_1(:)), ubound(pt_1(:))                 1            5
  lbound(iarr), ubound(iarr)                       0            4
  lbound(iarr(:)), ubound(iarr(:))                 1            5
  lbound(iarr(2:3)), ubound(iarr(2:3))             1            2
 
with g95 gcc version 4.0.3 (g95 0.90!) Sep 15 2006

  lbound(x%a ,1), ubound(x%a ,1)                   1            2
  lbound(y ,1), ubound(y ,1)                       0            1
  lbound(x%a ,2), ubound(x%a ,2)                   1            2
  lbound(y ,2), ubound(y ,2)                      -1            0
  lbound(typ), ubound(typ)                         0            4
  lbound(typ(:)), ubound(typ(:))                   1            5
  lbound(typ%in), ubound(typ%in)                   1            5
  lbound(typ(:)%in), ubound(typ(:)%in)             1            5
  lbound(pt_1), ubound(pt_1)                       1            5
  lbound(pt_1(:)), ubound(pt_1(:))                 1            5
  lbound(iarr), ubound(iarr)                       0            4
  lbound(iarr(:)), ubound(iarr(:))                 1            5
  lbound(iarr(2:3)), ubound(iarr(2:3))             1            2
 
with gfortran x86_64-unknown-linux-gnu, gcc version 4.2.0 20061009

  lbound(x%a ,1), ubound(x%a ,1)                  1             2
  lbound(y ,1), ubound(y ,1)                      0             1
  lbound(x%a ,2), ubound(x%a ,2)                  1             2
  lbound(y ,2), ubound(y ,2)                     -1             0
  lbound(typ), ubound(typ)                        0             4
  lbound(typ(:)), ubound(typ(:))                  1             5
  lbound(typ%in), ubound(typ%in)                  0             4        *
  lbound(typ(:)%in), ubound(typ(:)%in)            1             5
  lbound(pt_1), ubound(pt_1)                      1             5
  lbound(pt_1(:)), ubound(pt_1(:))                1             5
  lbound(iarr), ubound(iarr)                      0             4
  lbound(iarr(:)), ubound(iarr(:))                1             5
  lbound(iarr(2:3)), ubound(iarr(2:3))            1             2

  [akira] test/fortran> pgf -V

where * denotes the lines which differ from the ifort results.
Which one is right?  My understanding is that the lower bound of an array 
section is always one, but is typ(:)%in an array section? if yes (as I 
think so), pgf is wrong.  What about pointers and derived section? 
specially when the derived type is build from a defined array, does it 
inherit the bounds of the array?  I looked at the f2003 draft, but did not 
find a CLEAR answer to such questions.

TIA

Dominique


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]