http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47844
Summary: Pointer-valued function: Provide wrong result when dereferenced automatically after list-write Product: gcc Version: 4.6.0 Status: UNCONFIRMED Severity: minor Priority: P3 Component: fortran AssignedTo: unassig...@gcc.gnu.org ReportedBy: kdx1...@gmail.com Hello,I'm trying to compile Example 15.20 in Stephen J.Chapman's book Fortran 95/2003 for Scientists & Engineers. The purpose of the function is simple: "Return a pointer to every fifth element in a input rank 1 array". ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Code: PROGRAM test_pointer_value ! ! Purpose: ! Test pointer valued function ! ! Record of revisions: ! Date Programmer Description of change ! 02/22/2011 KePu Original code ! IMPLICIT NONE ! Data dictionary INTEGER,DIMENSION(10),TARGET::array=[1,3,5,7,9,11,13,15,17,19]! Array to be test INTEGER,dimension(2)::arrar_fifth INTEGER,POINTER,DIMENSION(:)::ptr_array=>NULL() ! Pointer to array INTEGER,POINTER,DIMENSION(:)::ptr_array_fifth=>NULL() ! Pointer return every fifth element of array ptr_array=>array ! Initialization ptr_array_fifth=>every_fifth(ptr_array) WRITE(*,*)ptr_array_fifth WRITE(*,*)every_fifth(ptr_array) CONTAINS FUNCTION every_fifth(ptr_array) RESULT(ptr_fifth) ! ! Purpose: ! To produce a pointer ot every fifth element in an ! input rand 1 array. ! ! Record of revisions: ! Date Programmer Description of change ! 02/22/2011 KePu Original code ! IMPLICIT NONE INTEGER,POINTER,DIMENSION(:)::ptr_fifth INTEGER,POINTER,DIMENSION(:),INTENT(in)::ptr_array INTEGER::low INTEGER::high low=LBOUND(ptr_array,1) high=UBOUND(ptr_array,1) ptr_fifth=>ptr_array(low:high:5) END FUNCTION every_fifth END PROGRAM test_pointer_value ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ The book says "The function can also be used in a location where an integer array is expected. Inthat case, the pointer returned by the function will automatically be dereferenced,and will print out the value by the pointer returned from the function". But after ran the program, two result prompt on the screen are different(The first line is right answer): 1 11 1 3 I'm not sure if it's a bug. Any help to my problem will be appreciated. Thank you.