How FORTRAN Maintains String Lengths (34972)
The information in this article applies to:
- Microsoft FORTRAN Compiler for MS-DOS 4.0
- Microsoft FORTRAN Compiler for MS-DOS 4.01
- Microsoft FORTRAN Compiler for MS-DOS 4.1
- Microsoft FORTRAN Compiler for MS-DOS 5.0
- Microsoft FORTRAN Compiler for MS-DOS 5.1
- Microsoft FORTRAN compiler for OS/2 4.1
- Microsoft FORTRAN compiler for OS/2 5.0
- Microsoft FORTRAN compiler for OS/2 5.1
This article was previously published under Q34972 SUMMARY
In ANSI FORTRAN, an application can pass character variables of varying
lengths to a subprogram by using the CHARACTER*(*) type declaration in
the subprogram. To use this technique, the subprogram must have access
to the strength length. In Microsoft FORTRAN, this information is
stored in an array of two-byte integers in a memory location that the
__FCclenv global variable points to. When a calling program calls a
subprogram that has character arguments, the string length table is
updated with the lengths of the parameter strings in the order in
which the arguments appear in the call or function reference. The
table reflects the length of each string argument because the calling
routine does not know in advance if the called subprogram declares the
character data as a fixed length or varying length string. The first
position in the table is reserved for the size of the string returned
from a character function. If the subprogram does not return a
character value, the first position in the table is undefined and
contains an arbitrary value.
Because the __FCclenv global variable contains the address of the
table of string lengths, the variable itself does not provide any
useful information. View the string length table by dereferencing the
value. Because FORTRAN does not define a method to deference a
pointer, another method is required. If an INTERFACE statement
declares a subprogram to receive an argument by value and the variable
in the subprogram is defined without the [value] attribute, the
subprogram receives the dereferenced value which it can return to its
caller. The subroutine must be declared in a separate file to avoid a
compiler error for the intentional mismatch in calling methods.
NOTE: __FCclenv is not defined in FORTRAN PowerStation.
Modification Type: | Major | Last Reviewed: | 12/1/2003 |
---|
Keywords: | KB34972 |
---|
|