|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
wws
Joined: 25 Oct 2007 Posts: 7 Location: California
|
Posted: Thu Oct 25, 2007 7:06 pm Post subject: Error when using a CHARACTER expression as actual arg |
|
|
Consider the following, which uses a character array expression using an ELEMENTAL function:
program ftn95bug
implicit none
character(8) :: indata(4) = (/ &
'12344321', '98766789', 'abcdefgh', 'ABCDEFGH' &
/)
call process (myfunc (indata))
contains
pure function myfunc (s)
character(*), intent(in) :: s(:)
character(len (s)) :: myfunc(size (s))
myfunc = s
end function
subroutine process (strings)
character(*), intent(in) :: strings(:)
print *, strings
end subroutine
end program
When compiling this with FTN95 I get the following error:
$ ftn95 ftn95bug.f90
[FTN95/Win32 Ver. 5.10.0 Copyright (c) Silverfrost Ltd 1993-2007]
NO ERRORS [<MYFUNC> FTN95/Win32 v5.10.0]
NO ERRORS [<PROCESS> FTN95/Win32 v5.10.0]
0008) call process (myfunc (indata))
*** In the INTERFACE to PROCESS, the first argument (STRINGS) is rank 1, but it is a scalar in this call
1 ERROR [<FTN95BUG> FTN95/Win32 v5.10.0]
*** Compilation failed
$
Since an array is given as the actual argument to the function, the result is also an array. So the above should be legal. And indeed, it compiles just fine on a number of other compilers. (Though it causes gfortran to ICE...)
Interestingly, an INTEGER version of the above test case compiles and runs fine. |
|
Back to top |
|
|
wws
Joined: 25 Oct 2007 Posts: 7 Location: California
|
Posted: Thu Oct 25, 2007 7:09 pm Post subject: |
|
|
Whoops - the above is a PURE version of the test, and also fails. Here is the ELEMENTAL version:
program ftn95bug
implicit none
character(8) :: indata(4) = (/ &
'12344321', '98766789', 'abcdefgh', 'ABCDEFGH' &
/)
call process (myfunc (indata))
contains
elemental function myfunc (s)
character(*), intent(in) :: s
character(len (s)) :: myfunc
myfunc = s
end function
subroutine process (strings)
character(*), intent(in) :: strings(:)
print *, strings
end subroutine
end program
$ ftn95 ftn95bug.f90
[FTN95/Win32 Ver. 5.10.0 Copyright (c) Silverfrost Ltd 1993-2007]
NO ERRORS [<MYFUNC> FTN95/Win32 v5.10.0]
NO ERRORS [<PROCESS> FTN95/Win32 v5.10.0]
0008) call process (myfunc (indata))
*** In the INTERFACE to PROCESS, the first argument (STRINGS) is rank 1, but it is a scalar in this call
1 ERROR [<FTN95BUG> FTN95/Win32 v5.10.0]
*** Compilation failed
$ |
|
Back to top |
|
|
brucebowler Guest
|
Posted: Thu Oct 25, 2007 8:44 pm Post subject: |
|
|
I think it's right...
process expects an array
Code: | subroutine process (strings)
character(*), intent(in) :: strings(:)
|
and myfunc expects a scalar
Code: | elemental function myfunc (s)
character(*), intent(in) :: s
character(len (s)) :: myfunc
|
But you're passing an array to myfunc, which returns a scalar. It seems to me you've got things backwards.
(of course I could be way off base on that :-) |
|
Back to top |
|
|
wws
Joined: 25 Oct 2007 Posts: 7 Location: California
|
Posted: Fri Oct 26, 2007 2:04 am Post subject: |
|
|
The shape of the result of an ELEMENTAL function is the same as the shape of its input argument(s). So my test case does illustrate the way things are supposed to work. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7925 Location: Salford, UK
|
Posted: Fri Oct 26, 2007 7:30 pm Post subject: |
|
|
This is a bug that we will investigate as soon as we can. |
|
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
|