"indirect" linked lists

"indirect" linked lists

Hi,

Is the following construct legal in Fortran-95?

! ---
type parCompObjType
type(dparType),pointer::par(:) ! parameters
endtype parCompObjType
! ---
type dparType
type(parCompObjType)::ftran_v2z
endtype dparType
! ---

This seems to compile and execute.

But if I switch the order of declarations (which seem symmetric, except for the dimension statement), the compiler complains...

! ---
type dparType
type(parCompObjType)::ftran_v2z
endtype dparType
! ---

type parCompObjType

type(dparType),pointer::par(:) ! parameters

endtype parCompObjType
! ---

error #6457: This derived type name has not been declared. [PARCOMPOBJTYPE]

Using (a more complex form of) this type of "indirect" linked list would allow me to simplify some of my code very dramatically, and it works on a simplified pilot code, but I am a little hesitant if this could create standard-compliance problems, or have some other problems I might be unaware of ...

could somebody shed some light on this?

thanks in advance.. dmitri

5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Your first code is legal Fortran 95 and the current version of Intel Visual Fortran compiles it successfully. Which version are you using?

The key is the POINTER attribute. With that, the type can be "any accessible type". Without it, the type must be previously defined.

Steve - Intel Developer Support

thanks Steve.

Indeed the first code compiles and runs correctly, and the second returns an error - which confused me a bit.

I just wasnt sure if this was some kind of extension. But your explanation re the POINTER made it clear (if somewhat esoteric - eg, why not allow for any accesible type whether or not a component is a POINTER?).

I am still on Intel Fortran 11.0.072. Will be upgrading to VS2010 soon and to the latest 11.X compiler.. before taking the plunge on the new Intel 12 compiler!

dmitri

Sorry, I tested the wrong one. Yes, the second case is not legal Fortran and the compiler correctly complains.

Steve - Intel Developer Support

Often, one needs to define a type which includes as a component pointers
to other variables of the type being defined (the phrase
"self-referential" is sometimes used as a label for such types).

Consider, for example, a binary tree where each node contains a five-character word, and is defined thus:

type tnode
  type (tnode), pointer :: left=>null(),right=>null()
  character(len=5),pointer :: name=>null()
  integer :: count=1
end type tnode

Compiling code that contains recursive definitions is hard for
compilers to do, but if only pointers are used (and if pointers to any
objects have the same footprint) it is not so hard.

You could think of the permitting of pointers to be used this way as an
invaluable loophole without which many programs would be much more
difficult to write.

Leave a Comment

Please sign in to add a comment. Not a member? Join today