View previous topic :: View next topic |
Author |
Message |
KL
Joined: 16 Nov 2009 Posts: 155
|
Posted: Wed Jan 13, 2010 12:05 pm Post subject: Error with Character Variable is not reported |
|
|
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
Code: |
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
|
Code: |
del comp.lis
del *.obj
del *.exe
ftn95 Test.f95 /checkmate /link >> comp.lis
sdbg Test.exe
|
|
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8210 Location: Salford, UK
|
Posted: Wed Jul 21, 2010 8:18 am Post subject: |
|
|
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. |
|
Back to top |
|
 |
JohnHorspool
Joined: 26 Sep 2005 Posts: 270 Location: Gloucestershire UK
|
Posted: Wed Jul 21, 2010 11:37 am Post subject: |
|
|
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! |
|
Back to top |
|
 |
IanLambley
Joined: 17 Dec 2006 Posts: 506 Location: Sunderland
|
Posted: Wed Jul 21, 2010 12:13 pm Post subject: |
|
|
If the two ranges do not overlap, then all will be well, otherwise who knows?
Ian |
|
Back to top |
|
 |
|