This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug fortran/41129] unassociated pointers are reported as associated by associated function in types



------- Comment #4 from burnus at gcc dot gnu dot org  2009-08-20 07:12 -------
(In reply to comment #0)
>   type S0
>      real, dimension(:), pointer :: P           ! NLEV
>   end type S0
> 
>   type (S0) :: x0
>   write (*,*)  'x0%P', associated(x0%P)

You have never initialized the pointer x0%P. Contrary to allocatables, pointers
have three states: associated, disassociated, or undefined. And your pointer is
in the "undefined" state.

Solutions:

a) If you want to stick to Fortran 90:
Add a "NULLIFY(x0%P)" after "type(S0) :: x0"

b) Using the Fortran 95, add a default initializer to the type declaration
   type S0
      real, dimension(:), pointer :: P => NULL()
   end type S0

c) Using a post-Fortran 95 compiler, which supports technical report TR 15581
or that part of Fortran 2003:

   type S0
      real, dimension(:), ALLOCATABLE :: P
   end type S0

   if (.not. ALLOCATED (X0%P)) allocate(X0%P(...))

Using (c) has the advantage that allocatables are nicer and faster.
(Allocatables can never leak memory and have only two states - allocated and
not allocated; and as they cannot not share the memory address with another
variable, the compiler can do better optimizations and generate thus faster
code.)

While most Fortran 95 compilers offer allocatable components, I think Absoft
does not do so (yet?).

> The textbook "Fortran 90 programing,  Ellis et al" says that the absoft
> compiler is producing the correct answer

Well, the authoritative source is the Fortran standard with all the corrigenda
(and answered interpretation requests), see 
http://gcc.gnu.org/wiki/GFortranStandards for links.

I am not sure whether Ellias et al. got it wrong, described it misleadingly or
whether you have just misreading it.

(For the relevant quotes from the standard, see comment 2.)


Can we close the bug as INVALID or do you still see something which gfortran
seems to do wrongly?


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41129


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]