Silverfrost Forums

Welcome to our forums

Compilation error - but why?

10 Apr 2013 4:20 #12030

Hi, the following generates an error at compile time...

!ftn95$free
    program test
    
    real*4  :: array(10)
    
    do i=1,10
      array(i)=float(i)
    end do
      
    call test1(array, 10)
    
    end
    
    subroutine test1 (array, anum)
    
    real*4  :: array(anum)
    integer anum
    
    aval=minval(array)
    write(*,*) aval
    
    end
    
    

I can code around it manually by swapping the two declarations in the subroutine, but my source is automatically generated from a list of function declarations supplied by a 3rd-party and in that list, the number of elements in the array are declared after the array itself and not with 'fortran integers' in mind, thus:

!void test1(ref System.Float[]& array, ref int anum)

so editing all the places where this occurs manually is a bit of a faff! is it fixable in the compiler?

K

10 Apr 2013 4:26 #12032

There should be a compile error here!

When ARRAY is declared, the variable ANUM hasn't been given a type, and so the compiler thinks its real (since it begins A). The compiler is not allowed to look ahead to see that ANUM is Integer. This is part of the Fortran Standard.

You can make it work by swapping the declaration, or by changing the name to NUM (anything starting I-N) ( or by changing ARRAY(ANUM) to ARRAY(*) if the size of the array isn't used implicitly in the subroutine, i.e. you don't use MAX(ARRAY) or anything similar).

Maybe you can ask the 3rd party to change how they generate the code to comply with the Fortran Standard? The error isn't in the C void declaration thats OK, its in the actual Fortran code, so maybe change how this is generated?

David.

Please login to reply.