ALLOCATABLE User-Defined Types and Strange Behavior

ALLOCATABLE User-Defined Types and Strange Behavior

Ritratto di michael-a-carr

I have something similar to following code:

--- type.f90 --- MODULE MTYPE TYPE NEWTYPE INTEGER, ALLOCATABLE :: N(:) END TYPE END MODULE --- subrt.f90 --- MODULE MSUBS CONTAINS SUBROUTINE SETUP(a) TYPE(NEWTYPE), INTENT(OUT) :: a ALLOCATE(a%n(1000)) a%n = 0 END SUBROUTINE END MODULE --- main.f90 --- PROGRAM TEST USE MTYPE TYPE(NEWTYPE) :: a CALL SETUP(a) END PROGRAM



When I run this program, it works fine until I return from the subroutine. When that happens, the array I allocated in the subroutine contains random values. Does the ALLOCATE command have scope in this case? i.e. Do I have to allocate in the outermost program unit or can I allocate in a subroutine like this?

Thank you,
Michael Carr

2 post / 0 new
Ultimo contenuto
Per informazioni complete sulle ottimizzazioni del compilatore, consultare l'Avviso sull'ottimizzazione
Ritratto di Community Admin

After inserting the line USE MTYPE in module MSUBS and USE MSUBS in program TEST so that the above compiles, it looks like the first few elements of a%n are incorrect. Compaq just put this allocatable components stuff in their compiler and they don't have all the kinks worked out yet. You should send them a bug report when you see misbehavior like this. Probably the above would work if you used the F95-compatible method of a pointer component rather than an allocatable component.

Accedere per lasciare un commento.