Silverfrost Forums

Welcome to our forums

Error with Character Variable is not reported

13 Jan 2010 11:05 #5705

Problem: “Error with Character Variable is not reported”

This is only a minor “problem”: The handbook says that the use of a character variable on both sides of an assignment statement is not permitted. As the test program shows, this is not detected or reported by /Checkmate.

However, it seems to me that the above statement is not fully correct since a –meaningful- assignment of the form

Character_Variable (i:j) = Character_Variable (k:l)

should be (and is) treated correctly.

Klaus Lassmann

  Winapp
  Program Test
      Implicit None
      Integer                            :: i
      Character (len = 1), Dimension (3) :: Text
      Character (len = 3)                :: Text_all

      Text (1) = 'A'
      Text (2) = 'B'
      Text (3) = 'C'

      Text_all = ''
      Do i = 1,3
        Text_all = Text_all // Text (i)    ! not allowed, but not reported
      End Do
        write (*,*) 'Text_all =', Text_all ! Result wrong

      Do i = 1,3
        Text_all (i:i) = Text (i)
      End Do
        write (*,*) 'Text_all =', Text_all ! Result correct

        Text_all (1:2) = Text_all (2:3)    ! assignement statement
        write (*,*) 'Text_all =', Text_all ! Result correct


      Text (1) = 'a'
      Text (2) = 'b'
      Text (3) = 'c'
      Text_all (1:1) = Text (1)
      Do i = 2,3
        Text_all (1:i) = Text_all (1:i-1) // Text (i) ! allowed ???
      End Do
        write (*,*) 'Text_all =', Text_all            ! Result correct

  End Program Test




del comp.lis
del *.obj
del *.exe
ftn95 Test.f95 /checkmate /link >> comp.lis
sdbg  Test.exe
21 Jul 2010 7:18 #6653

This program compiles and runs with FTN95 even when using /ISO. It also runs successfully on a third party compiler. I have not attempted to try to work out what the Fortran Standard says should happen.

21 Jul 2010 10:37 #6658

If my memory is correct, this was not allowed (or produce unpredictable results) in fortran 77 running on a VAX/VMS machine, and you would use an additional character string to get around the problem. That is how I have written my code ever since!

21 Jul 2010 11:13 #6660

If the two ranges do not overlap, then all will be well, otherwise who knows? Ian

Please login to reply.