 |
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
KennyT
Joined: 02 Aug 2005 Posts: 318
|
Posted: Wed Apr 10, 2013 5:20 pm Post subject: Compilation error - but why? |
|
|
Hi, the following generates an error at compile time...
Code: | !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 |
|
Back to top |
|
 |
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Wed Apr 10, 2013 5:26 pm Post subject: |
|
|
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. _________________ Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl |
|
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
|