allocatable dummy and pointer 
Author Message
 allocatable dummy and pointer

Hi,

    Are allocatable dummy and pointer the same thing? When I tried to
compile the following example, all compilers I tested (g95, gfortran,
intel fortran) think t1 and t2 are the same. Is this correct?

thanks,
Chengkun

      module test_module

      interface test
        module procedure t1
        module procedure t2
      end interface

      contains

      subroutine t1(a,b)

      integer, dimension(:,:), allocatable, intent(inout) :: a
      integer :: b

      end subroutine

      subroutine t2(b,c)

      integer, dimension(:,:), pointer :: b
      integer :: c

      end subroutine

      end module test_module

      program test

      use test_module

      end



Wed, 07 Sep 2011 14:56:19 GMT  
 allocatable dummy and pointer

Quote:

> ? ? Are allocatable dummy and pointer the same thing?

No, they are quite different.

Quote:
> When I tried to
> compile the following example, all compilers I tested (g95, gfortran,
> intel fortran) think t1 and t2 are the same. Is this correct?

Their arguments do not differ in a way that the standard defines for
disambiguation: in simple words, the number and/or types and/or ranks
of the arguments (see also "Fortran 95/2003 Explained", p. 93).

Regards,

Mike Metcalf



Wed, 07 Sep 2011 16:36:12 GMT  
 allocatable dummy and pointer

Quote:
> Hi,

> ? ? Are allocatable dummy and pointer the same thing? When I tried to
> compile the following example, all compilers I tested (g95, gfortran,
> intel fortran) think t1 and t2 are the same. Is this correct?

> thanks,
> Chengkun

> ? ? ? module test_module

> ? ? ? interface test
> ? ? ? ? module procedure t1
> ? ? ? ? module procedure t2
> ? ? ? end interface

> ? ? ? contains

> ? ? ? subroutine t1(a,b)

> ? ? ? integer, dimension(:,:), allocatable, intent(inout) :: a
> ? ? ? integer :: b

> ? ? ? end subroutine

> ? ? ? subroutine t2(b,c)

> ? ? ? integer, dimension(:,:), pointer :: b
> ? ? ? integer :: c

> ? ? ? end subroutine

> ? ? ? end module test_module

> ? ? ? program test

> ? ? ? use test_module

> ? ? ? end

Dear Chengkun,

Yes, the compilers are correct here.  Please see 14.1.2.3 "Unambiguous
generic procedure references" of the Fortran 95 standard.  You can
obtain a draft of this standard and others from http://gcc.gnu.org/wiki/GFortranStandards.
In brief, procedure references can be distinguished by arguments that
differ in type, kind and rank.  For this reason,

      integer, dimension(:,:), allocatable, intent(inout) :: a
      integer, dimension(:,:), pointer :: b

are the same.  In fact, in gfortran, at least, the descriptor that is
passed is identical as can be verified by using the option -fdump-tree-
original and examining the tree-dump file.

With best regards

Paul



Wed, 07 Sep 2011 17:21:02 GMT  
 allocatable dummy and pointer
Hi Mike and Paul,

   Thanks for the explanation! The references are very useful.

   I also notice one thing, the intel compiler actually only gives
warning about the ambiguity of the interface in the example. Maybe it
think they are actually different.

   What I am trying to accomplish is to allocate array in a module and
the module would have same interface for pointer or allocatable
variables. So it looks like it is not possible?

thanks,
Chengkun


Quote:

> > Hi,

> > ? ? Are allocatable dummy and pointer the same thing? When I tried to
> > compile the following example, all compilers I tested (g95, gfortran,
> > intel fortran) think t1 and t2 are the same. Is this correct?

> > thanks,
> > Chengkun

> > ? ? ? module test_module

> > ? ? ? interface test
> > ? ? ? ? module procedure t1
> > ? ? ? ? module procedure t2
> > ? ? ? end interface

> > ? ? ? contains

> > ? ? ? subroutine t1(a,b)

> > ? ? ? integer, dimension(:,:), allocatable, intent(inout) :: a
> > ? ? ? integer :: b

> > ? ? ? end subroutine

> > ? ? ? subroutine t2(b,c)

> > ? ? ? integer, dimension(:,:), pointer :: b
> > ? ? ? integer :: c

> > ? ? ? end subroutine

> > ? ? ? end module test_module

> > ? ? ? program test

> > ? ? ? use test_module

> > ? ? ? end

> Dear Chengkun,

> Yes, the compilers are correct here. ?Please see 14.1.2.3 "Unambiguous
> generic procedure references" of the Fortran 95 standard. ?You can
> obtain a draft of this standard and others fromhttp://gcc.gnu.org/wiki/GFortranStandards.
> In brief, procedure references can be distinguished by arguments that
> differ in type, kind and rank. ?For this reason,

> ? ? ? integer, dimension(:,:), allocatable, intent(inout) :: a
> ? ? ? integer, dimension(:,:), pointer :: b

> are the same. ?In fact, in gfortran, at least, the descriptor that is
> passed is identical as can be verified by using the option -fdump-tree-
> original and examining the tree-dump file.

> With best regards

> Paul



Thu, 08 Sep 2011 14:33:24 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. allocatable non-dummy local variables and pointers to them

2. Avoiding "allocatable dummy arrays" extended feature

3. Allocatable dummy argument

4. Dummy Arguments, allocatable?

5. Allocatable dummy arguments in f90

6. Unallocated Allocatable as Dummy Argument to be Allocated inside Subroutine

7. Allocatable as dummy argument does not work

8. Can allocatable dummies be optional?

9. dummy allocatable question

10. Pointer points to sub's dummy argument

11. dummy argument pointers

12. dummy array arguments with the pointer attribute

 

 
Powered by phpBB® Forum Software