(j3.2006) finalizing undefined entities -- odd text in 6.6.4

Robert Corbett Robert.Corbett
Wed Mar 19 04:32:14 EDT 2008


Jim Xia wrote:
> 
> j3-bounces at j3-fortran.org wrote on 03/18/2008 05:03:35 PM:
> 
>  > Really??  My interpretation has been that including the stat= specifier
>  > should prevent the program from aborting.
>  >
> 
> It would be really useful if it does.  Try this program to see if stat= 
> does do magic :-)
> 
> 
>     real, pointer :: a, b
>    
>     allocate (a)
>    
>     b => a
>    
>     deallocate (b, stat=i1)
>    
>     deallocate(a, stat=i2)
>    
>     print *, i1, i2
>     end

I ran the following syntactically modified program using Sun Fortran:

       PROGRAM MAIN
         POINTER A, B

         ALLOCATE(A)
         B => A
         DEALLOCATE(B, STAT=I1)
         DEALLOCATE(A, STAT=I2)
         PRINT *, I1, I2
       END

The output of the program is

  0 1185

The error message assciated with error code 1185 is

  Error 1185:  deallocating an object not allocated by an ALLOCATE
               statement

The error message might be a bit confusing, but it is accurate.  After
the first DEALLOCATE statement, the object is no longer allocated, and
so it is not allocated by an ALLOCATE statement.

Nonetheless, I agree with your basic point.  After the first DEALLOCATE
statement, the target pointer allocation status of A is undefined.
Therefore, the second DEALLOCATE statement violates the requirement of
the first sentence of Section 6.3.3.2 of the Fortran 2003 standard.
Therefore, the program is not a standard-conforming program, and any
behavior whatever is permitted.

Bob Corbett



More information about the J3 mailing list