Silverfrost Forums

Welcome to our forums

Strange runtime errors when returning an array

10 Dec 2013 8:28 #13438

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:

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:

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.

10 Dec 2013 8:52 #13439

Should result variable be declared as

real :: x(res(1),res(2),res(3),res(4),4)

10 Dec 2013 10:07 #13440

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?

11 Dec 2013 5:06 #13443

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...

11 Dec 2013 7:26 #13445

The line I posted [u:97432e5e8c]is [/u:97432e5e8c]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.

11 Dec 2013 8:28 #13447

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:

    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...

12 Dec 2013 7:59 #13460

I have logged this for investigation.

19 Mar 2014 2:44 #13874

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.

Please login to reply.