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

Oddly indexed Pointer array

mattsdad
Débutant
460 Visites

I need to know if the pointer to the array called 'AA' in the code below will actuall reference the several 'AA' elements of the 'ex' array. (The compiler makes no complaints.)

...

TYPE symbol
REAL, POINTER :: arr(:) => NULL()
END TYPE symbol

TYPE

E
REAL :: AA, BB, CC
END TYPE E

TYPE

P
TYPE(E), ALLOCATABLE, DIMENSION(:) :: ex
END TYPE P

TYPE

Bod
TYPE(P) :: pro
END TYPE Bod

TYPE

(Bod), ALLOCATABLE, DIMENSION(:) :: body
REAL, POINTER :: AA(:), BB(:), CC(:)
TYPE(symbol) :: sym
REAL, POINTER :: pnt
...
ALLOCATE(body(MAXBODIES))
...
ALLOCATE(body(B)%pro%ex(MAX))
CALL init_ex(body(B)) ! ..%ex(I)%AA gets data here
...
AA => body(B)%pro%ex(:)%AA
CALL insert_array_in_symbol_table('AA', AA)
! passes AA as REAL, POINTER pt(:) and sets symb(I)%arr => pt
...
sym = getSymbol('AA')
pnt => sym%arr(N)
! where N is in 1..MAX
...

My concern is that the REAL array AAhas other data between itssequential elements. Will theAA pointer array still index to the expected data elements?

Will 'pnt'point to theexpected AA element?

I appologize in advance for the convoluted qu estion. I am writing a parser around this data structure, andI fealt that waiting till the parser is completelydone to get to a test would be a waste of time ifthepointer arraydoesn't work.

0 Compliments
2 Réponses
Steven_L_Intel1
Employé
460 Visites
It should work. AA will point to noncontiguous data and will have a non-unit stride in its descriptor. I assume that the corresponding dummy argument of insert_array_in_symbol_table declares the argument as an assumed-shape array (:) and that an explicit interface is provided.
0 Compliments
mattsdad
Débutant
460 Visites

MADsblionel:
I assume that the corresponding dummy argument of insert_array_in_symbol_table declares the argument as an assumed-shape array (:)

Yes

MADsblionel:
and that an explicit interface is provided.

and Yes (by use of the module it is part of.)

0 Compliments
Répondre