Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Lower bounds in a pointer

John4
Valued Contributor I
458 Views

Hi,

Maybe someone else (me?) already posted a similar question, but I got tired of browsing page results in the new (global) forum search, so I apologize for that.

Is there any way, as of Fortran 95, to get the correct lower bounds in a pointer to the component of a derived type array? None of the options I tried in the code below seem to work ---with the last option (The Fortran 2003 way, according to MR&C), I get "error #6731: Object is not a pointer object". Maybe that feature is not yet implemented, but the error message is not helpful at all.

program test
implicit none
type :: t2
integer :: c
end type
type :: t1
type(t2), allocatable :: b(:,:)
end type
type(t1), target :: a
integer, pointer :: c(:,:)

allocate (a%b(-1:100, 0:100))

c => a%b%c
print *, LBOUND(c)
print *, UBOUND(c)
read *

c => a%b(:,:)%c
print *, LBOUND(c)
print *, UBOUND(c)
read *

c => a%b(-1:,0:)%c
print *, LBOUND(c)
print *, UBOUND(c)

c(-1:,0:) => a%b%c
print *, LBOUND(c)
print *, UBOUND(c)

end program test

0 Kudos
1 Solution
TimP
Honored Contributor III
458 Views
>gfortran john.f90
john.f90:28:

c(-1:,0:) => a%b%c
1
Error: Pointer bounds remapping at (1) is not yet implemented in gfortran
________________________________________________
Of several compilers I tried, none accepted it, and only this one deviates from "not a pointer object."

View solution in original post

0 Kudos
3 Replies
TimP
Honored Contributor III
459 Views
>gfortran john.f90
john.f90:28:

c(-1:,0:) => a%b%c
1
Error: Pointer bounds remapping at (1) is not yet implemented in gfortran
________________________________________________
Of several compilers I tried, none accepted it, and only this one deviates from "not a pointer object."
0 Kudos
jimdempseyatthecove
Honored Contributor III
458 Views


a%b%c is an invalid syntax given the types

a%b is a type(t2) array

a%b(index)%cwould bea reference to a scalar integer

integer, pointer :: c(:,:)
...
c => a%b%c ! (integer array pointer) => (integer scalar)

Not correct (unless the compiler implicitly sets cwith bounds of(1:1))

Jim Dempsey

0 Kudos
John4
Valued Contributor I
458 Views


a%b%c is an invalid syntax given the types

If a%b%c is invalid, doesn't that defeat the purpose of using derived types in an array programming language? I've always considered it correct, by analogy with, say A(:) versus A (i.e., slice versus whole array). So, if a%b(:,:)%c is valid, then a%b%c should also be valid... Or, can it be that a%b(:,:)%c is invalid as well?

0 Kudos
Reply