test for allocatable function (f95 extension)

Uttam Pawar uttamp@us.ibm.com
Tue Nov 29 19:00:00 GMT 2005


$ cat test.f90  
         program no_leak
             real, dimension(100) :: x, y
             y(:size(compact(x))) = compact(x)**2
           contains
           function compact(x)
             real,allocatable,dimension(:) :: compact
             real,dimension(:),intent(in) :: x
             integer             :: n
             allocate(compact(n))
           end function compact
          end

$ test.f90
gfortran test.f90

 In file test.f90:6

             real,allocatable,dimension(:) :: compact
                                                    1
Error: ALLOCATABLE attribute conflicts with FUNCTION attribute at (1)
 In file test.f90:9

             allocate(compact(n))
                            1
Error: Syntax error in ALLOCATE statement at (1)
 In file test.f90:3

             y(:size(compact(x))) = compact(x)**2
                    1
Error: 'array' argument of 'size' intrinsic at (1) must be an array

No errors when compiled with Lahey's fortran source check, it compiles
with following warnings,
"Compiling program unit no_leak at line 1:
  2004-I: "SOURCE.F90", line 3: 'y' is set but never used.
 Internal subprogram name(compact)
  3622-I: "SOURCE.F90", line 5: An allocatable array function 'compact' is an extended feature.
  2064-I: "SOURCE.F90", line 6: If local allocatable array 'compact' is currently allocated when procedure exited by execution of a RETURN or END statement, it is not deallocated.
  2008-I: "SOURCE.F90", line 7: Dummy argument 'x' not used in this subprogram.
  2005-W: "SOURCE.F90", line 9: 'n' is used but never set.
Encountered 0 errors, 1 warning, 4 informations in file SOURCE.F90.
Compiling file SOURCE.F90."


Thanks,

Uttam



More information about the Fortran mailing list