public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "Kdx1999 at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/47844] New: Pointer-valued function: Provide wrong result when dereferenced automatically after list-write Date: Tue, 22 Feb 2011 07:07:00 -0000 [thread overview] Message-ID: <bug-47844-4@http.gcc.gnu.org/bugzilla/> (raw) 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.
next reply other threads:[~2011-02-22 5:34 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top 2011-02-22 7:07 Kdx1999 at gmail dot com [this message] 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
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-47844-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).