replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - Strange runtime errors when returning an array
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 

Strange runtime errors when returning an array

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



Joined: 17 Oct 2013
Posts: 8

PostPosted: Tue Dec 10, 2013 9:28 pm    Post subject: Strange runtime errors when returning an array Reply with quote

I am having trouble with a function that returns a (small) 5-dimensional array. The behavior is so strange, I think it must be caused by a bug in the compiler - though I am pretty new to Fortran so I could be wrong.

I'm running the latest compiler (version 7.0.0.0) on Windows 8.

I have written some simplified code which triggers the problem:

Code:
program main

use testModule

implicit none

integer, parameter :: r1=10,r2=2,r3=10,r4=2
integer, parameter :: res(4) = (/r1,r2,r3,r4/)

real :: x(r1,r2,r3,r4,4)

x = testFunction(res)

print*,"Press ENTER to close"
read*

end program main


with the following module in its own ft95 file:

Code:
module testModule

implicit none

contains

    function testFunction(res) result(x)
        integer, intent(in) :: res(4)
        real :: x(res(1),res(2),res(2),res(4),4)
       
        x = 1
       
    end function testFunction

end module testModule


At the moment, the following error at occurs runtime:
"Attempt to call a routine with an inconsistent INTERFACE relating to the return type" (with the debugger pointing to the line where testFunction is called).

But as I have been fiddling around trying to figure out the problem, I have also seen access violation and out of memory errors. Furthermore, the problem goes away when the module is included in the same ft95 file as the main program - but not unless the IDE is first restarted. So it all seems pretty bizarre.

I'm going to try to find a workaround, but any help would be appreciated.
Back to top
View user's profile Send private message
davidb



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Tue Dec 10, 2013 9:52 pm    Post subject: Reply with quote

Should result variable be declared as

real :: x(res(1),res(2),res(3),res(4),4)
_________________
Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl
Back to top
View user's profile Send private message
Brad



Joined: 17 Oct 2013
Posts: 8

PostPosted: Tue Dec 10, 2013 11:07 pm    Post subject: Reply with quote

Hi David,

I'm not sure what you are asking. Are you saying I should use the line you posted (it looks identical to me), or that I should not use that syntax and should do something else?
Back to top
View user's profile Send private message
Brad



Joined: 17 Oct 2013
Posts: 8

PostPosted: Wed Dec 11, 2013 6:06 am    Post subject: Reply with quote

Update: Old code (using similar functions) that used to work a few weeks ago now also generates errors. So there must be some sort of more general problem. Maybe I updated the compiler incorrectly or something. I am trying to re-install everything...
Back to top
View user's profile Send private message
davidb



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Wed Dec 11, 2013 8:26 am    Post subject: Reply with quote

The line I posted is different!

Look carefully at the function.

I think there may be a compiler bug here, but its worth correcting your code first. You code (with my correction) works with some other compilers.
_________________
Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl
Back to top
View user's profile Send private message
Brad



Joined: 17 Oct 2013
Posts: 8

PostPosted: Wed Dec 11, 2013 9:28 am    Post subject: Reply with quote

Sorry David, I see it now. But you're right - it is not the main problem. In fact, the error can be triggered with an even simpler function:
Code:

    function testFunction() result(x)
        real :: x(10)
        x = 1
       
    end function testFunction


Luckily I have found a workaround: I have reverted back to version 6.3.5.0 of the compiler, and the code now works - but only if I compile in the .NET framework. With Win32, the error remains. I can't remember for sure if this was the case for the version 7 of the compiler, but I don't think either mode worked...
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Thu Dec 12, 2013 8:59 am    Post subject: Reply with quote

I have logged this for investigation.
Back to top
View user's profile Send private message AIM Address
PaulLaidler
Site Admin


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

PostPosted: Wed Mar 19, 2014 3:44 pm    Post subject: Reply with quote

For the time being, this false run-time error report has been "fixed" by removing the run-time argument checking process when a function returns an array result (either explicitly via a RESULT clause or implicitly via the function name).

The immediate work-around is to use /INHIBIT_CHECK 6 when /CHECK is used.

The "fix" will be included in 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