Passing allocatable arrays as a assumed shape argument?



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...

.



Relevant Pages

  • Re: Passing allocatable arrays as a assumed shape argument?
    ... I tried to pass a dynamically allocated array as an assumed shape ... object to a subroutine, in GFortran: ... Make your subroutine an internal procedure to the main program OR put it ... Mike Metcalf ...
    (comp.lang.fortran)
  • Re: Win32 API and gfortran
    ... Call Win32 API from gfortran is possible, ... SUBROUTINE FortranSub() ... END SUBROUTINE FortranSub ...
    (comp.lang.fortran)
  • Re: Allocatable arrays in derived types
    ... The thing that makes me feel a little queasy is that gfortran ... doesn't have the capability to express the stride in units ... subroutine str1 ... character), pointer:: p ...
    (comp.lang.fortran)
  • Re: fortran 90/95 standart
    ... SUBROUTINE eval ... IMPLICIT REAL ... Can you update to a newer compiler 4.0.1 is fairly in gfortran development? ... The previous version was mixing C and fortran subroutines and is not used anymore It is not a good candidate for testing a new compiler! ...
    (comp.lang.fortran)
  • Re: locating numerical differences in g77 to gFortran conversion
    ... The code comprises several hundred thousand lines of ... mostly fortran 77 code, with some ancient fortran, c and c++ thrown in. ... I've managed to build the project with gcc 4 / gFortran. ... Correct argument type on a subroutine or function call. ...
    (comp.lang.fortran)