replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - Compiler bug or feature?
forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Compiler bug or feature?

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
johnbarnes



Joined: 28 May 2014
Posts: 11
Location: Oxfordshire, UK

PostPosted: Sat May 31, 2014 8:48 am    Post subject: Compiler bug or feature? Reply with quote

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
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8210
Location: Salford, UK

PostPosted: Sat May 31, 2014 5:46 pm    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
davidb



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Sun Jun 01, 2014 11:09 am    Post subject: Reply with quote

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
View user's profile Send private message
mecej4



Joined: 31 Oct 2006
Posts: 1899

PostPosted: Sun Jun 01, 2014 1:45 pm    Post subject: Reply with quote

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
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8210
Location: Salford, UK

PostPosted: Thu Jan 15, 2015 9:30 am    Post subject: Reply with quote

This issue has now been fixed for the next release.
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group