Silverfrost Forums

Welcome to our forums

Error when using a CHARACTER expression as actual arg

25 Oct 2007 6:06 #2378

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.

25 Oct 2007 6:09 #2379

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 $

26 Oct 2007 1:04 #2381

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.

26 Oct 2007 6:30 #2384

This is a bug that we will investigate as soon as we can.

Please login to reply.