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

Structures and pointers

Intel_C_Intel
Employee
471 Views
Can I declare pointer locations in a structure constructor? I have two structures that refer to the same structure array by a pointer, and I would like to set these up at compile time.

My example code looks like thus:

program TestExtractSpec
!
   implicit none
!
! declarations
!
   type :: Descriptor
      integer(4) vartype                         ! Type of variable
      character*80 Name                          ! Name of variable
   end type
!   
   type :: ExtractSpec
      integer(4) start                           ! Start of variable in record
      integer(4) length                          ! Length of variable
      type(Descriptor), pointer :: description   ! Associated information
   end type
!
   type :: OutputSpec
      Integer(4) location                        ! Column number
      type(Descriptor), pointer :: description   ! Associated information
   end type
!
! data
!
   type (Descriptor), dimension(2) :: Descriptors = (/ &
      Descriptor(1, "Hello 1"), &
      Descriptor(2, "Hello 2") /)

!
   type (ExtractSpec), dimension(2) :: twoRecordSpecs = (/ &
      ExtractSpec(18, 16, %LOC(Descriptors(1))), &    
      ExtractSpec(61, 16, %LOC(Descriptors(2)))  /) 
!
   type (OutputSpec), dimension(2) :: twoPrintSpecs = (/ &
      OutputSpec(2, loc(Descriptors(1))), &    
      OutputSpec(1, loc(Descriptors(2)))  /) 
!
! more stuff
!

end program

but it doesn't compile (CVF 6.6 on Windows XP). The sticking point is in the %loc() or loc() initialisations for the pointers - can this be done? Any suggestions welcome!

All the best,
Eddie
0 Kudos
1 Reply
Steven_L_Intel1
Employee
471 Views
Not like that - Fortran 90 pointers aren't compatible with %LOC. I think the only pointer you can use in a constructor is NULL().

Steve
0 Kudos
Reply