Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29004 Discussions

pointer in namelist, but no compiler error?

j0e
New Contributor I
381 Views
I see in intel fortran and elsewhere that a pointer cannot be specified in a NAMELIST statement; however, when I do so anyway, no compiler errors occur. Furthermore, it seems to work just fine in that reading the namelist file updates the pointer and associated target as expected.

Given that it is not supposed to work, I won't use it, but why does it work at all (or have I misread something)?
cheers,
-joe

[fortran]module glob
   implicit none
   integer, parameter:: n = 10
   real(8), target:: x(n)
   real(8), pointer:: ptox1, ptox2
   
   namelist /test/ x, ptox1
   
   contains
   subroutine initialize ()
      ptox1 => x(1)
      ptox2 => x(2)
      return
   end subroutine initialize
end module glob

program pointertests
   use glob
   implicit none
   
   call initialize ()
   
   open(unit=1,file='test.dat',status='old')
   read(1,nml=test)
   close(unit=1)
   
   write(6,*) 'x: ', x(1:2)
   write(6,*) 'ptox1: ', ptox1  
   write(6,*) 'ptox2: ', ptox2  
   
   stop
end program pointertests[/fortran]


where test.data is:
[plain]&test
x(1:2) = 1.0, 2.0
ptox1 = 10.
/[/plain]

0 Kudos
1 Reply
Steven_L_Intel1
Employee
381 Views
This is legal in Fortran 2003. If you ask for F90 or F95 standards checking, it will complain.
0 Kudos
Reply