Intent with regard to pointer components of derived types.
From: Toby White (tow21_at_cam.ac.uk)
Date: 01/22/04
- Next message: Jugoslav Dujic: "Re: How to get the directory my application installed"
- Previous message: Pierre Asselin: "Re: help reg ALLOCATABLE arrays with INTENT statement"
- Next in thread: Michael Metcalf: "Re: Intent with regard to pointer components of derived types."
- Reply: Michael Metcalf: "Re: Intent with regard to pointer components of derived types."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 22 Jan 2004 16:23:41 +0000
Sorry if this has already been covered recently - I had a look
through google and couldn't find anything obvious.
So I have a structure rather like:
Type struct_map
Real, Allocatable, Dimension(:) :: map_data
Integer :: counter
End Type struct_map
Type struct
Real, Alloctable, Dimension(:) :: data
Type(struct_map) :: Pointer
End Type struct
where a given instance of struct_map may be shared between a number of
instances of struct. For the purpoese of garbage collection, therefore,
struct_map has a counter that may be incremented and decremented to
keep track of the number of instances of struct pointing to it.
If I then have a subroutine which trivially generates a new instance
of struct from an old, copying the data across, but sharing the
struct_map, it seemes reasonable to me to cast it as:
Subroutine copy_struct(struct_old, struct_new)
Type(struct_old), Intent(In) :: struct_old
Type(struct_new), Intent(InOut) :: struct_new
Call destroy_struct(struct_new)
struct_new % data = struct_old % data
struct_new % map => struct_old % map
!Next line is of interest.
struct_old % counter = struct_old % counter + 1
End Subroutine copy_struct
According to Intel's ifort, this is forbidden since I am altering
a subcomponent of an Intent(In) dummy argument.
However, if I were to change the offending line to
struct_new % counter = struct_new % counter + 1
then I would achieve *exactly* the same effect, but get round the
Intent(In).
Lahey, though (at least the oldish version I have) has no such
problem with the code, though.
>From a brief perusal of the F95 standard, Intel's reading seems
correct, but seems to me to render the notion of Intent(In)
completely pointless.
Could some kind soul tell me which compiler is correct here?
Toby
-- Dr. Toby White, Dept. of Earth Sciences, Downing Street, Cambridge CB2 3EQ. UK Email: <tow21@cam.ac.uk> Tel: +44 1223 333409 Fax: +44 1223 333450
- Next message: Jugoslav Dujic: "Re: How to get the directory my application installed"
- Previous message: Pierre Asselin: "Re: help reg ALLOCATABLE arrays with INTENT statement"
- Next in thread: Michael Metcalf: "Re: Intent with regard to pointer components of derived types."
- Reply: Michael Metcalf: "Re: Intent with regard to pointer components of derived types."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|