 |
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
Brad
Joined: 17 Oct 2013 Posts: 8
|
Posted: Tue Dec 10, 2013 9:28 pm Post subject: Strange runtime errors when returning an array |
|
|
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 |
|
 |
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Tue Dec 10, 2013 9:52 pm Post subject: |
|
|
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 |
|
 |
Brad
Joined: 17 Oct 2013 Posts: 8
|
Posted: Tue Dec 10, 2013 11:07 pm Post subject: |
|
|
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 |
|
 |
Brad
Joined: 17 Oct 2013 Posts: 8
|
Posted: Wed Dec 11, 2013 6:06 am Post subject: |
|
|
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 |
|
 |
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Wed Dec 11, 2013 8:26 am Post subject: |
|
|
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 |
|
 |
Brad
Joined: 17 Oct 2013 Posts: 8
|
Posted: Wed Dec 11, 2013 9:28 am Post subject: |
|
|
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 |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8210 Location: Salford, UK
|
Posted: Thu Dec 12, 2013 8:59 am Post subject: |
|
|
I have logged this for investigation. |
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8210 Location: Salford, UK
|
Posted: Wed Mar 19, 2014 3:44 pm Post subject: |
|
|
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 |
|
 |
|
|
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
|