next up previous contents index
Next: Arrays as Arguments Up: Variables as Dummy Arguments Previous: ExpressionsSubscripts, and Substrings

Passed-length Character Arguments

A character dummy argument will have its length set automatically to that of the corresponding actual argument if the special length specification of *(*) is used.

To illustrate this, here is a procedure to count the number of vowels in a character string. It uses the intrinsic function LEN to determine the length of its dummy argument, and the INDEX function to see whether each character in turn is in the set "AEIOU" or not.

 
       INTEGER FUNCTION VOWELS(STRING) 
       CHARACTER*(*) STRING 
       VOWELS = 0 
       DO 25, K = 1,LEN(STRING) 
          IF( INDEX('AEIOU', STRING(K:K)) .NE. 0) THEN 
               VOWELS = VOWELS + 1 
          END IF 
25     CONTINUE 
       END
Note that the function has a data type which is not the default for its initial letter so that it will usually be necessary to specify its name in a INTEGER statement in each program unit which references the function.

This passed-length mechanism is recommended not only for general-purpose software where the actual argument lengths are unknown, but in all cases unless there is a good reason to specify a dummy argument of fixed length.

There is one restriction on dummy arguments with passed length: they cannot be operands of the concatenation operator (//) except in assignment statements. Note that the same form of length specification ``*(*)" can be used for named character constants but with a completely different meaning: named constants are not subject to this restriction.



Mario Storti
Wed Nov 4 19:32:56 ART 1998