Passing allocatable arrays as a assumed shape argument?
- From: mischamegens@xxxxxxxxxxx
- Date: Tue, 30 Oct 2007 11:23:13 -0700
Hi all,
I tried to pass a dynamically allocated array as an assumed shape
object to a subroutine, in GFortran:
PROGRAM HELLO
IMPLICIT NONE
REAL, DIMENSION(:), ALLOCATABLE :: a
ALLOCATE(a(3))
a(1)=111
a(2)=123
a(3)=333
CALL s(a,3)
WRITE(6,*) 'Finished'
DEALLOCATE(a)
END
SUBROUTINE s(b,n)
IMPLICIT NONE
REAL, DIMENSION(:) :: b
INTEGER n
REAL c
write(6,*) 'Hello'
c=b(2)
write(6,*) 'Done'
END
I thought that this would work, but when running (GFortran 4.3.0 on
Cygwin), I get
$ gfc alloctest.f
$ ./a.exe
Hello
7 [main] a 2808 _cygtls::handle_exceptions: Error while
dumping state (probably corrupted stack)
Segmentation fault (core dumped)
I can get it to work by declaring
REAL b(n)
in the subroutine, but shouldn't it work without the n as well?
Is there something obvious that I am overlooking?
Best regards,
Mischa
PS: If I comment out the c=b(2) assignment, the program runs as
expected, without any corrupted stack issues...
.
- Follow-Ups:
- Re: Passing allocatable arrays as a assumed shape argument?
- From: Michael Metcalf
- Re: Passing allocatable arrays as a assumed shape argument?
- Prev by Date: Re: End of file
- Next by Date: Re: Passing allocatable arrays as a assumed shape argument?
- Previous by thread: opening char variable data file
- Next by thread: Re: Passing allocatable arrays as a assumed shape argument?
- Index(es):
Relevant Pages
|
|