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 

Trim in a subroutine argument

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



Joined: 05 Jul 2006
Posts: 268

PostPosted: Fri Mar 11, 2022 7:51 am    Post subject: Trim in a subroutine argument Reply with quote

The following module defines a subroutine with a character array as an argument, and a simple program calls the subroutine. The call passes a scalar character, but uses square brackets to treat the scalar as an array with just one element. The first call compiles ok, but the second call uses the intrinsic function Trim, generating a compilation error message. I understand that Trim could not be used if there were multiple elements to c of different length, but since there is only one the error message that "Array constructor elements must be of fixed length" seems misleading if not erroneous. I don't know what the standard says, but since "Trim(c)" returns a character scalar, and "c" without Trim is a character scalar, it seems reasonable to assume that the second call should compile. The code compiles and runs with the intended result with NAGWare.

Code:
Module m
Contains
 Subroutine s (c)
  Character(Len=*), Dimension(:), Intent(In) :: c
 End Subroutine s
End Module m
Program p
 Use m
 Character(Len=4) :: c = 'c   '
 Call s ([c])
 Call s ([Trim(c)])
End Program p
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Fri Mar 11, 2022 10:42 am    Post subject: Reply with quote

Simon

This code fails to compile with FTN95 but is OK with other compilers that I have tried.

It compiles if you use /ignore 1076 but gives incorrect results for 64 bits and a runtime failure for 32 bits.

As far as the Standard is concerned, it is possible that the FTN95 error report is correct for Fortran 95 but was relaxed in a later standard.

It seems strange to me that one would use TRIM in an array constructor or that one would want to pass an array constructor as an argument.

Perhaps as a work-around you could apply the TRIM within the subroutine.
Back to top
View user's profile Send private message AIM Address
simon



Joined: 05 Jul 2006
Posts: 268

PostPosted: Fri Mar 11, 2022 6:31 pm    Post subject: Reply with quote

Thanks for the response, Paul.
I can see that the use of Trim in the array constructor is somewhat problematic. I'll look into a work around.
Back to top
View user's profile Send private message
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