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 

Inonsistent behaviour when passing an section of an array to a subroutine...

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





PostPosted: Fri Feb 24, 2006 1:32 pm    Post subject: Inonsistent behaviour when passing an section of an array to Reply with quote

Can you tell me why the following piece of code prints 10, instead of 5? If it really is 10, why does an attempt to access element 6 result in an array bounds error???

program test
real a(10)
forall (i=1:10) a(i) = real(i)
call sub(a(1:5))
stop
end
subroutine sub(a)
real a(*)
write (6,*) size(a)
return
end

Thanks!
Bruce
Back to top
PaulLaidler
Site Admin


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

PostPosted: Fri Feb 24, 2006 3:25 pm    Post subject: Inonsistent behaviour when passing an section of an array to Reply with quote

Bruce

You get the right answer when you use an interface and an assumed shape array.
I would have to check the Fortran 77 Standard to see if FTN95 is behaving correctly for your assumed size array.

program test
interface
subroutine sub(a)
real a(Smile
end subroutine
end interface
real a(10)
forall (i=1:10) a(i) = real(i)
call sub(a(1:5))
stop
end
subroutine sub(a)
real a(Smile
write (6,*) size(a)
return
end


Back to top
View user's profile Send private message AIM Address
brucebowler
Guest





PostPosted: Mon Feb 27, 2006 7:12 am    Post subject: Inonsistent behaviour when passing an section of an array to Reply with quote

Paul,

But the question you left unanswered (which was, I guess, the "real" question) is - If I try and access array element 6 in SUB, I get an "array out of bounds" error. *THAT* is inconsistant with size(a) = 10. I know I can fix it by using interfaces, but am curious about the inconsitancy.

Thanks!
Bruce
Back to top
PaulLaidler
Site Admin


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

PostPosted: Mon Feb 27, 2006 10:32 am    Post subject: Inonsistent behaviour when passing an section of an array to Reply with quote

Bruce

I tried your code on a third party compiler and it gave a very large value for the size.

As far as I can tell from a quick inspection, the Fortran 90 standard does not say what should happen when a (Fortran 90) array section is passed as an assumed-size (Fortran 77) argument.

The standards committee probably worked on the assumption that array sections would be passed as assumed-shape arrays.

I do not think that we can class this as a bug.

The amount of work needed to "fix" the compiler (to give the more intuitive result) would depend on whether or not the required information is immediately to hand. Chances are that the information is not to hand and that this is why the compiler writer stuck to the old standard and simply passed the size of the whole array. If a change were feasible, we would also have to assess the possibility that we might break some existing user's code by making a change.

In the mean time it is apparent that array sections must be passed as assumed-shape arrays for FTN95 and for portability to other compilers.

Now perhaps to the real answer to your question...

FTN95 passes additional hidden arguments in /CHECK mode etc. These are used to provide runtime checking (of array bounds etc) during development. The additional information is not available for use in the SIZE intrinsic which has to work for both checked and unchecked code.
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