As discussed many times, one has to roll one's own array of pointers
(otherwise one gets a pointer to an array). OK, a bit ugly, but it
works, as in the the programme after my .sig.
However, when one of these constructs is on the right side of an
assignment statement, one CANNOT use array syntax, but must reference
them individually. The relevant section of the standard is 6.1.2, as
Digital Fortran90 kindly points out (now THAT's what I call an error
message!). What is the reason for this restriction? If there is no
technical reason, will the restriction be lifted in the future?
I could see a problem in that the result would be ambiguous if, to make
an example out of the code below, BLA(1)%P pointed to J(2) and BLA(2)%P
pointed to J(1). However, since J doesn't have the TARGET attribute,
the compiler knows that this can't be the case. I could be really ugly
and EQUIVALENCE I and J, but again the compiler could know this.
(Should a compiler complain in this case if J doesn't have the TARGET
attribute? If not, another reason not to use EQUIVALENCE:)
--
Phillip Helbig Email ... [log in to unmask]
Nuffield Radio Astronomy Laboratories Tel. ..... +44 1477 571 321 (ext. 297)
Jodrell Bank Fax ................. +44 1477 571 618
Macclesfield Telex ................. 36149 JODREL G
UK-Cheshire SK11 9DL Web .... http://www.jb.man.ac.uk/~pjh/
===============================================================================
PROGRAM TESTY
TYPE PBOX
INTEGER, POINTER :: P
END TYPE PBOX
TYPE (PBOX), DIMENSION(:), ALLOCATABLE :: BLA
INTEGER, DIMENSION(2) :: J(2)
INTEGER, DIMENSION(2), TARGET :: I=(/3,4/)
INTEGER :: K
ALLOCATE(BLA(2))
DO, K = 1, 2, 1
BLA(K)%P => I(K)
END DO
! The following statements are not allowed.
!BLA(:)%P => I(:)
!BLA%P => I
! But a DO loop works:
DO, K = 1, 2, 1
J(K) = BLA(K)%P
END DO
PRINT*, J(:)
PRINT*, J(1)
PRINT*, J(2)
END PROGRAM TESTY
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|