Character data

The checking mechanism provides the following diagnostic checks for character data:

  1. That an argument of type character is of sufficient length for its declared dummy size. For example, in CHECK mode, the following program would cause a run-time error:

CHARACTER*20 A
. . .
CALL CHSUB(A)
. . .
END
SUBROUTINE CHSUB(X)
CHARACTER*30 X
. . .
END

The error could be prevented in this case by declaring X in the subroutine as follows:

CHARACTER(*) X

so that X would assume the character length of the actual argument.

  1. That substring expressions are valid. There are two possible sources of error that may arise when using a substring reference of the form A(I:J):

  • either the value of I is greater than the value of J or

  • the value of I is less than 1 or the value of J is greater than the declared or assumed length of the character variable or array element.

All of the character assignment statements in the following program would cause a run-time error:

CHARACTER*20 A,B(20)
. . .
I = 0
J = 21
K = 4
L = 3
A(I:) = 'X'
A(1:J) = 'XXX'
B(3)(K:L) = 'XXX'
END

 

 

Basket
Empty
 
Copyright © 1999-2024 Silverfrost Limited