public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/47844] New: Pointer-valued function: Provide wrong result when dereferenced automatically after list-write
@ 2011-02-22  7:07 Kdx1999 at gmail dot com
  2011-02-22  8:37 ` [Bug fortran/47844] " burnus at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: Kdx1999 at gmail dot com @ 2011-02-22  7:07 UTC (permalink / raw)
  To: gcc-bugs

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: unassigned@gcc.gnu.org
        ReportedBy: Kdx1999@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.


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2012-06-29 18:09 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-22  7:07 [Bug fortran/47844] New: Pointer-valued function: Provide wrong result when dereferenced automatically after list-write Kdx1999 at gmail dot com
2011-02-22  8:37 ` [Bug fortran/47844] " burnus at gcc dot gnu.org
2011-02-22 15:35 ` [Bug fortran/47844] I/O: data transfer statement: Array stride ignored for pointer-valued function results burnus at gcc dot gnu.org
2011-03-01 13:20 ` [Bug fortran/47844] " burnus at gcc dot gnu.org
2011-10-05 10:02 ` dominiq at lps dot ens.fr
2011-10-05 10:22 ` pault at gcc dot gnu.org
2011-10-05 14:36 ` paul.richard.thomas at gmail dot com
2011-10-05 15:04 ` burnus at gcc dot gnu.org
2011-10-05 21:40 ` dominiq at lps dot ens.fr
2011-10-05 22:20 ` pault at gcc dot gnu.org
2011-10-08 10:19 ` pault at gcc dot gnu.org
2012-02-19 20:23 ` tkoenig at gcc dot gnu.org
2012-06-29 18:09 ` mikael at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).