forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Error when using a CHARACTER expression as actual arg

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
wws



Joined: 25 Oct 2007
Posts: 7
Location: California

PostPosted: Thu Oct 25, 2007 7:06 pm    Post subject: Error when using a CHARACTER expression as actual arg Reply with quote

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
View user's profile Send private message
wws



Joined: 25 Oct 2007
Posts: 7
Location: California

PostPosted: Thu Oct 25, 2007 7:09 pm    Post subject: Reply with quote

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
View user's profile Send private message
brucebowler
Guest





PostPosted: Thu Oct 25, 2007 8:44 pm    Post subject: Reply with quote

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

PostPosted: Fri Oct 26, 2007 2:04 am    Post subject: Reply with quote

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
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7925
Location: Salford, UK

PostPosted: Fri Oct 26, 2007 7:30 pm    Post subject: Reply with quote

This is a bug that we will investigate as soon as we can.
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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