Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29229 Discussões

pointer initialization with =>null()

Sergey_L_
Principiante
2.731 Visualizações

I am puzzled why this program compiles program ntest interface subroutine itakepointer(p) integer, dimension(:), pointer :: p => null() end subroutine itakepointer end interface end program ntest I do ifort -stand f95 -warn all ntest.f90 If I explicitly add `save' it fails program ntest interface subroutine itakepointer(p) integer, dimension(:), pointer, save :: p => null() end subroutine itakepointer end interface end program ntest ntest.f90(4): error #6453: The SAVE attribute conflicts with other declarations.

integer, dimension(:), pointer, save :: p => null() -----------------------------------------------^ compilation aborted for ntest.f90 (code 1) For me it seems the following part of the standard implies that those two programs should be equivalent and not confirming. http://j3-fortran.org/doc/standing/archive/007/97-007r2/ascii/c05.txt If initialization is =>NULL (), object-name shall be a pointer, and its initial association status is disassociated. Use of =>NULL () in a scoping unit is a reference to the intrinsic function NULL. The presence of initialization implies that object-name is saved, except for an object-name in a named common block or an object-name with the PARAMETER attribute. The implied SAVE attribute may be reaffirmed by explicit use of the SAVE attribute in the type declaration statement, or by inclusion of the object-name in a SAVE statement (5.2.4). ifort version 13.1.1 Linux 2.6.37.6-24-desktop #1 SMP PREEMPT 2012-10-18 22:36:08 +0200 x86_64 x86_64 x86_64 GNU/Linux

0 Kudos
1 Solução
Steven_L_Intel1
Funcionário
2.731 Visualizações

Neither of these are standard-conforming as they violate this constraint from F2008:

C506 (R503) An initialization shall not appear if object-name is a dummy argument, a function result, an object in a named common block unless the type declaration is in a block data program unit, an object in blank common, an allocatable variable, or an automatic object.

In the second case, the compiler notices you are trying to SAVE a dummy argument, which is not allowed. But it should also reject the initialization. I will report this to the developers.

Ver solução na publicação original

5 Respostas
Sergey_L_
Principiante
2.731 Visualizações

I am puzzled why this program compiles

program ntest
  interface
     subroutine itakepointer(p)
       integer, dimension(:), pointer :: p => null()
     end subroutine itakepointer
  end interface
end program ntest

I do
ifort -stand f95  -warn all ntest.f90

If I explicitly add `save' it fails
program ntest
  interface
     subroutine itakepointer(p)
       integer, dimension(:), pointer, save :: p => null()
     end subroutine itakepointer
  end interface
end program ntest

ntest.f90(4): error #6453: The SAVE attribute conflicts with other declarations.  


       integer, dimension(:), pointer, save :: p => null()
-----------------------------------------------^
compilation aborted for ntest.f90 (code 1)

For me it seems the following part of the standard implies that those
two programs should be equivalent and not confirming.

http://j3-fortran.org/doc/standing/archive/007/97-007r2/ascii/c05.txt
If initialization is =>NULL (), object-name shall be a pointer, and
its initial association status is disassociated.  Use of =>NULL () in
a scoping unit is a reference to the intrinsic function NULL.

The presence of initialization implies that object-name is saved,
except for an object-name in a named common block or an object-name
with the PARAMETER attribute.  The implied SAVE attribute may be
reaffirmed by explicit use of the SAVE attribute in the type
declaration statement, or by inclusion of the object-name in a SAVE
statement (5.2.4).

ifort version 13.1.1
Linux 2.6.37.6-24-desktop #1 SMP PREEMPT 2012-10-18 22:36:08 +0200 x86_64 x86_64 x86_64 GNU/Linux

Steven_L_Intel1
Funcionário
2.732 Visualizações

Neither of these are standard-conforming as they violate this constraint from F2008:

C506 (R503) An initialization shall not appear if object-name is a dummy argument, a function result, an object in a named common block unless the type declaration is in a block data program unit, an object in blank common, an allocatable variable, or an automatic object.

In the second case, the compiler notices you are trying to SAVE a dummy argument, which is not allowed. But it should also reject the initialization. I will report this to the developers.

Mark_Lewy
Contribuidor valorado I
2.731 Visualizações

I'd argue that your first program (without save) should also fail to compile because p is a dummy argument.

According to Metcalf, Reid, and Cohen, Fortran 95/2003 explained (7.5.3), a pointer that is initialised in its declaration must not be a dummy argument or function result.

Izaak_Beekman
Novo colaborador II
2.731 Visualizações

I think Steve is agreeing with you.

Steven_L_Intel1
Funcionário
2.731 Visualizações

I think Mark and I were posting at the same time. Both of us agree that the programs are incorrect and that the compiler should reject both.
 

Responder