Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Fortran > Zero-size array...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 16 Topic 8100 of 8908
Post > Topic >>

Zero-size arrays

by relaxmike <michael.baudin@[EMAIL PROTECTED] > Apr 4, 2008 at 07:40 AM

Hi fortran gurus !

After several hours of head-scratching, I found a strange behaviour
of my fortran compilers against arrays of size 0.
I reduced the problem to the source code below.

In fortran 90, one can allocate an array with a size of 0.
What I understand is that, on this zero-size array,
the "allocated" intrinsic answers "T" and the "size" intrinsic answers
0.
In my case, this situation appears because of a recursive function,
because the algorithm is based on a "divide and conquer" method.
What I do not understand is why the zero-size array of the following
code appears to be un-allocated only with gfortran compiler,
although I know that it really is allocated !

module testmod
  type, public :: t_type
     character(LEN=3D1), dimension(:), allocatable :: chars
  end type t_type
contains
  recursive function recursivefunc ( this ) result ( match )
    type(t_type), intent(in) :: this
    type(t_type) :: subpattern
    logical :: thisalloc
    integer :: thislength
    logical :: match
    thisalloc =3D allocated ( this % chars )
    if ( .NOT. thisalloc ) then
       write ( 6 , * ) "STOP with error !"
       stop
    endif
    thislength =3D size ( this % chars )
    if ( thislength =3D=3D 0 ) then
       match =3D .true.
       return
    endif
    allocate ( subpattern % chars (0) )
    match =3D recursivefunc ( subpattern )
  end function recursivefunc
end module testmod

program testprog
  use testmod
  implicit none
  type(t_type) :: this
  logical :: match
  allocate ( this % chars ( 10 ))
  match =3D recursivefunc ( this )
  print * , "match :", match
end program testprog

What I don't understand is that my code does not behave the
same with g95, gfortran and IVF 8.0.
With gfortran :

> gfortran  test.f90 -o test.exe
> test.exe
STOP with error !

With g95 :

> g95  test.f90 -o test.exe
> test.exe
match : T

Intel Visual Fortran 8 exhibits the same behaviour as g95.

In fact, I don't really known what the fortran 90 standard says about
0-size arrays ?

Any help will be appreciated.

Best regards,

Micha=EBl
 




 16 Posts in Topic:
Zero-size arrays
relaxmike <michael.bau  2008-04-04 07:40:31 
Re: Zero-size arrays
Tobias Burnus <burnus@  2008-04-04 08:26:22 
Re: Zero-size arrays
"James Van Buskirk&q  2008-04-04 10:15:20 
Re: Zero-size arrays
Fei Liu <fei.liu@[EMAI  2008-04-04 14:42:51 
Re: Zero-size arrays
nospam@[EMAIL PROTECTED]   2008-04-04 14:01:11 
Re: Zero-size arrays
Fei Liu <fei.liu@[EMAI  2008-04-07 09:33:23 
Re: Zero-size arrays
nospam@[EMAIL PROTECTED]   2008-04-07 08:37:35 
Re: Zero-size arrays
Ken Plotkin <kplotkin@  2008-04-06 13:15:43 
Re: Zero-size arrays
glen herrmannsfeldt <g  2008-04-04 08:41:35 
Re: Zero-size arrays
Gordon Sande <g.sande@  2008-04-04 17:21:23 
Re: Zero-size arrays
GaryScott <garylscott@  2008-04-04 12:29:15 
Re: Zero-size arrays
Tobias Burnus <burnus@  2008-04-04 15:27:54 
Re: Zero-size arrays
"Gerry Ford" &l  2008-04-06 03:54:16 
Re: Zero-size arrays
Terence <tbwright@[EMA  2008-04-06 15:49:11 
Re: Zero-size arrays
Beliavsky <beliavsky@[  2008-04-07 13:29:38 
Re: Zero-size arrays
Beliavsky <beliavsky@[  2008-04-07 13:38:28 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Nov 22 16:52:20 CST 2008.