View previous topic :: View next topic |
Author |
Message |
johnbarnes
Joined: 28 May 2014 Posts: 11 Location: Oxfordshire, UK
|
Posted: Sat May 31, 2014 8:48 am Post subject: Compiler bug or feature? |
|
|
I have put together the example below to illustrate FTN95 behaviour that surprised me. Look at the commented statement that assigns values to the dest array. FTN95 accepted this without warning and implemented it as though the statement was:
dest(ii(1): jj(1): -1) = 6
gFORTRAN however, does not accept the original statement and, I think correctly, reports an error "Array index must be scalar".
So, is the FTN95 behaviour here a bug or a feature?
Here is the code:
integer, dimension(10) :: dest
integer, dimension(2) :: ii
integer, dimension(2) :: jj
dest = 0
ii(1) = 4
ii(2) = 9
jj(1) = 2
jj(2) = 7
dest(ii: jj: -1) = 6 ! What does this do? |
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8210 Location: Salford, UK
|
Posted: Sat May 31, 2014 5:46 pm Post subject: |
|
|
I am guessing that this is not valid Fortran so FTN95 should report a compilation error.
However, it is treating it as
dest(ii(1): jj(1): -1) = 6
which in this context is
dest(4: 2: -1) = 6
which means
dest(4) = 6; dest(3) = 6; dest(2) = 6
i.e start at 4 and step to 2 in steps of -1. |
|
Back to top |
|
 |
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Sun Jun 01, 2014 11:09 am Post subject: |
|
|
I agree FTN95 should ideally be providing a compiler error with the above code.
However, arrays can be used as indices like in the following example, so there is a need to ensure such array indices are supported if any "fix" is implemented.
Code: |
INTEGER I(3)
REAL A(6)
A = 0.0
I = (/2, 4, 6/) ! Sets I(1)=2, I(2)=4, I(3)=6
A(I) = 6.0 ! Sets A(2)=6, A(4)=6, A(6)=6
|
_________________ Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl
Last edited by davidb on Mon Jun 02, 2014 4:29 pm; edited 1 time in total |
|
Back to top |
|
 |
mecej4
Joined: 31 Oct 2006 Posts: 1899
|
Posted: Sun Jun 01, 2014 1:45 pm Post subject: |
|
|
The following extracts from section 6.5.3.1 of the Fortran Standard lead one to conclude that the subscript expression "ii: jj: -1" is invalid, since "dest", "ii" and "jj" have been declared as integer arrays.
Quote: | R621 subscript-triplet is [ subscript ] : [ subscript ] [ : stride ]
R619 subscript is scalar-int-expr
|
|
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8210 Location: Salford, UK
|
Posted: Thu Jan 15, 2015 9:30 am Post subject: |
|
|
This issue has now been fixed for the next release. |
|
Back to top |
|
 |
|