public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "burnus at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/54788] ICE on pointer-array element assignment Date: Wed, 03 Oct 2012 09:14:00 -0000 [thread overview] Message-ID: <bug-54788-4-V1hprKjdg5@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-54788-4@http.gcc.gnu.org/bugzilla/> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54788 --- Comment #3 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-10-03 09:14:26 UTC --- (In reply to comment #0) > allocate(vec(2)) > allocate(vec(0)%arr(4,4)) I assume you have a C background. In Fortran, by default the lower array bound is one. Thus, with "allocate(vec(2))" you allocated an array of size 2, which can be accessed via vec(1) and vec(2). Thus, you access invalid memory for "vec(0)". However, you can also allocate via allocate(vec(0:2)) then you have a size-3 array, where vec(0), vec(1) and vec(2) are valid. (you could also have negative bounds, e.g. "allocate(vec(-2:0))".) The other point is, as Janus already mentioned: Fortran only has pointers to arrays but not an array of pointers. Thus "vec(1)" and "vec(2)" point to the same array, one to the first element and one to the second element. In terms of the standard, allocate(vec(2)) allocates an anonymous target (a rank-1, size-2 array) and then pointer assigns that target to the (scalar) pointer "vec". Thus "vec" is a pointer to a size-2 array with the lower bound "1" and upper bound "2". (In reply to comment #2) > Thus, if you want to do bounds remapping, you have to specify a range, e.g. > vec(1:1) => vec(0:0) Remark to my example: While it is syntactically correct, accessing "vec(0:0)" isn't (out of bounds). It were okay for "allocate(vec(0:2))" - but still, it wouldn't do what you expect: "vec(1)" would then point to the first element of the array, "vec(2)" would be in principle the second element (and in practice accessible), but but one may not use it: In "vec(1:1) =>" one has explicitly told the compiler that one only wants to point to a size-1 array.
next prev parent reply other threads:[~2012-10-03 9:14 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top 2012-10-02 21:48 [Bug fortran/54788] New: " slayoo at staszic dot waw.pl 2012-10-03 0:02 ` [Bug fortran/54788] " janus at gcc dot gnu.org 2012-10-03 7:33 ` burnus at gcc dot gnu.org 2012-10-03 9:14 ` burnus at gcc dot gnu.org [this message] 2012-10-03 10:45 ` slayoo at staszic dot waw.pl 2012-10-09 18:58 ` slayoo at staszic dot waw.pl 2013-06-27 9:17 ` dominiq at lps dot ens.fr 2013-07-01 8:01 ` burnus at gcc dot gnu.org 2013-07-01 8:13 ` burnus 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-54788-4-V1hprKjdg5@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).