- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have something similar to following code:
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
--- 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
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page