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 

An unexpected single step exception has occurred
Goto page Previous  1, 2, 3
 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
davidb



Joined: 17 Jul 2009
Posts: 557
Location: UK

PostPosted: Wed Jun 15, 2011 12:57 pm    Post subject: Reply with quote

In one of my Fortran books it says that when a CHARACTER dummy argument is declared to have a specific length, the actual argument must be the same length or longer. If it is longer, the leading characters are passed up to the specified length.

See the code below (which compiles and runs OK).

If this is the correct behaviour, then it possibly provides a "consistency" argument for the behaviour seen with ICHAR (though ICHAR is an intrinsic and different rules might apply). But I don't know if there's a general rule about this in the standard for Fortran 95, or if its just a F2003 extension that is supported -- if there is ICHAR could be off the hook. Question

This is in the Fortran 2003 standard:

"Fortran 2003, 12.4.1.2 Actual arguments associated with dummy data objects

If a scalar dummy argument is of type default character, the length len of the dummy argument shall be less than or equal to the length of the actual argument. The dummy argument becomes associated with the leftmost len characters of the actual argument.
"

Code:

module foo
contains
   function first(c)
      character(len=1), intent (in) :: c !< Means actual argument has len >= 1
      character(len=1) :: first
      first = c
   end function
end module foo

program anon
   use foo
   implicit none
   character(len=10) :: str
   str = 'ABCDEFGHIJ'
   print '("First character of ",a," is ",a)', str, first(str)
end program anon
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
Goto page Previous  1, 2, 3
Page 3 of 3

 
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